Onvif协议-设备搜索

导读

本人通过百度查找相关资料发现,网上实现Onvif的搜索多过于复杂,同时发现没有人使用“RemoteDiscoveryBindingProxy” 这个类实现相关的搜索功能(个人查找结论)。RomoteDiscoveryBindingProxy类是通过 gsoap生成c++的版本

补充知识

ws-discovery

实现步骤

1.通过gsoap生成“RomoteDiscoveryBindingProxy”

@ gsoap的详细使用过程(生成的是C++版本):

@ 生成“RomoteDiscoveryBindingProxy”生成命令(本人采用本地文件*.xml和*.wsdl文件内容完全一样):

wsdl2h -o Remote.h -n web -y -t "./typemap.dat" Onvif\wsdl\remotediscovery.xml 
soapcpp2 -i -I IMPORT -L -C -w -x -y Remote.h

@ 将生成的文件*.nsmap,*.h,*.cpp 和 stdsoap2.h,stdsoap2.cpp 一同copy到自己的工程中

@编写搜索功能:


 #include "soapRemoteDiscoveryBindingProxy.h"
 #include "onvif-gsoap/wsdd.nsmap"
 #include "string"
int main()
{
    char *was_To = "urn:schemas-xmlsoap-org:ws:2005:04:discovery";  
    char *was_Action = "http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe";  
    //这个就是传递过去的组播的ip地址和对应的端口发送广播信息      
    const char *soap_endpoint = "soap.udp://239.255.255.250:3702"; 

    wsdd__HelloType helloType;
    wsdd__ResolveType resolveType;

    wsdd__ProbeType req; 
    wsdd__ProbeMatchesType resp;
    //UUID 好最后是变化的否则 onvif 组播服务可能只回复一次
    std::string guid_string = "uuid:68749E8A-2EDD-49C0-ABF8-45E0733911BF";

    //这样是默认一个网卡Ip发送组播
    RemoteDiscoveryBindingProxy remote(soap_endpoint);
    //等待数据返回超时时间
    remote.recv_timeout = 3;

    //初始化soap_header的相关内容。
    //第一种方法。
    remote.soap_header((char*)guid_string.c_str(),nullptr,nullptr,nullptr,nullptr,was_To,was_Action,nullptr);
    //第二种方法(这种方法是C语言的方法)
    /*
    SOAP_ENV__Header header;
    soap_default_SOAP_ENV__Header(&remote,&header);
    header.wsa__MessageID = (char *)guid_string.c_str();
    header.wsa__To = was_To;
    header.wsa__Action = was_Action;
    remote.header = &header;
    */
    //第三种
    /*
    remote.header->wsa__MessageID = (char *)guid_string.c_str();
    remote.header->wsa__To = was_To;
    remote.header->wsa__Action = was_Action;
    */

    soap_default_wsdd__ProbeType(&remote, &req);
    req.Types = "dn:NetworkVideoTransmitter";

    remote.Probe(req,resp);

}