onvif 客户端的发现

1、解压:unzip -X gsoap_2.8.10.zip 编译

2、下载:

wget http://www.onvif.org/onvif/ver10/network/wsdl/remotediscovery.wsdl

3、复制:

cp gsoap-2.8/gsoap/typemap.dat .

4、在typemap.dat 中添加:

#Use gSOAP 2.8.10 and up. In the typemap.dat file used by wsdl2h, add:
#	ONVIF recommended prefixes
tds	= "http://www.onvif.org/ver10/device/wsdl"
tev	= "http://www.onvif.org/ver10/events/wsdl"
tls	= "http://www.onvif.org/ver10/display/wsdl"
tmd	= "http://www.onvif.org/ver10/deviceIO/wsdl"
timg	= "http://www.onvif.org/ver20/imaging/wsdl"
trt	= "http://www.onvif.org/ver10/media/wsdl"
tptz	= "http://www.onvif.org/ver20/ptz/wsdl"
trv	= "http://www.onvif.org/ver10/receiver/wsdl"
trc	= "http://www.onvif.org/ver10/recording/wsdl"
tse	= "http://www.onvif.org/ver10/search/wsdl"
trp	= "http://www.onvif.org/ver10/replay/wsdl"
tan	= "http://www.onvif.org/ver20/analytics/wsdl"
tad	= "http://www.onvif.org/ver10/analyticsdevice/wsdl"
tdn	= "http://www.onvif.org/ver10/network/wsdl"
tt	= "http://www.onvif.org/ver10/schema"
#	OASIS recommended prefixes
wsnt	= "http://docs.oasis-open.org/wsn/b-2"
wsntw	= "http://docs.oasis-open.org/wsn/bw-2"
wsrfbf	= "http://docs.oasis-open.org/wsrf/bf-2"
wsrfr	= "http://docs.oasis-open.org/wsrf/r-2"
wsrfrw  = "http://docs.oasis-open.org/wsrf/rw-2"
wstop	= "http://docs.oasis-open.org/wsn/t-1"
#	WS-Discovery 1.0 remapping
wsdd10__HelloType		= | wsdd__HelloType
wsdd10__ByeType			= | wsdd__ByeType
wsdd10__ProbeType		= | wsdd__ProbeType
wsdd10__ProbeMatchesType	= | wsdd__ProbeMatchesType
wsdd10__ProbeMatchType		= | wsdd__ProbeMatchType
wsdd10__ResolveType		= | wsdd__ResolveType
wsdd10__ResolveMatchesType	= | wsdd__ResolveMatchesType
wsdd10__ResolveMatchType	= | wsdd__ResolveMatchType
#	SOAP-ENV mapping
SOAP_ENV__Envelope	= struct SOAP_ENV__Envelope { struct SOAP_ENV__Header *SOAP_ENV__Header; _XML SOAP_ENV__Body; }; | struct SOAP_ENV__Envelope
SOAP_ENV__Header	= | struct SOAP_ENV__Header
SOAP_ENV__Fault		= | struct SOAP_ENV__Fault
SOAP_ENV__Detail	= | struct SOAP_ENV__Detail
SOAP_ENV__Code		= | struct SOAP_ENV__Code
SOAP_ENV__Subcode	= | struct SOAP_ENV__Subcode
SOAP_ENV__Reason	= | struct SOAP_ENV__Reason


5、把编译好的wsdl2h,soapcpp2复制到本目录
6、./wsdl2h -o onvif.h -c -s -t typemap.dat remotediscovery.wsdl

7、./soapcpp2 -c onvif.h -x -I /workplace/mywork/onvif/gsoap-x86/gsoap-2.8/gsoap/import

8、复制文件:

cp gsoap-2.8/gsoap/stdsoap2.* .

9、测试代码:

#include <iostream>
#include "wsdd.nsmap"
#include "soapH.h"
using namespace std;
int main()
{
    struct soap *soap;
    struct wsdd__ProbeType req;
    struct __wsdd__ProbeMatches resp;
    struct wsdd__ScopesType sScope;
    struct SOAP_ENV__Header header;
    int count = 0;
    int result = 0; 

    char guid_string[100];

     soap = soap_new(); 
    if(soap==NULL)
    {
        return -1;
    }
 
    soap_set_namespaces(soap, namespaces); 

    soap->recv_timeout = 5;		//超过5秒钟没有数据就退出
    soap_default_SOAP_ENV__Header(soap, &header);
 
    header.wsa__MessageID = guid_string;
    header.wsa__To= "urn:schemas-xmlsoap-org:ws:2005:04:discovery";
    header.wsa__Action= "http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe";
    soap->header = &header;

    soap_default_wsdd__ScopesType(soap, &sScope);
    sScope.__item = "";
    soap_default_wsdd__ProbeType(soap, &req);
    req.Scopes = &sScope;
    req.Types = "";

    result = soap_send___wsdd__Probe(soap, "soap.udp://239.255.255.250:3702", NULL, &req);

    do{
         result = soap_recv___wsdd__ProbeMatches(soap, &resp); 
         if (soap->error) 
         { 
             cout<<"soap error:"<<soap->error<<soap_faultcode(soap)<<"---"<<soap_faultstring(soap)<<endl; 
             result = soap->error; 
             break;
         } 
         else
         {
            cout<<"========================================="<<endl;
 
            cout<<"Match size:"<<resp.wsdd__ProbeMatches->__sizeProbeMatch<<endl;
            cout<<"xsd-unsignedInt:"<<resp.wsdd__ProbeMatches->ProbeMatch->MetadataVersion<<endl;
            cout<<"scopes item:"<<resp.wsdd__ProbeMatches->ProbeMatch->Scopes->__item<<endl;
            //cout<<"scopes matchby:"<<resp.wsdd__ProbeMatches->ProbeMatch->Scopes->MatchBy<<endl;
            cout<<"QName:"<<resp.wsdd__ProbeMatches->ProbeMatch->Types<<endl;
            cout<<"xsd:string:"<<resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.Address<<endl;
            cout<<"xsd:QName:"<<resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.PortType<<endl;
            cout<<"wsa:ServiceNameType:"<<resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.ServiceName<<endl;
            cout<<"sequence of elements:"<<resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.__size<<endl;
            cout<<"xsd:anyType:"<<resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.__anyAttribute<<endl;
            cout<<"endpoint any:"<<resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.__any<<endl;
            cout<<"wsdd:UriListType:"<<resp.wsdd__ProbeMatches->ProbeMatch->XAddrs<<endl;
         }
     }while(1);

    soap_destroy(soap); // remove deserialized class instances (C++ only) 
    soap_end(soap);		// clean up and remove deserialized data
    soap_done(soap);

    return result;
}

编译:g++ cc.cpp soapC.c  stdsoap2.cpp soapClient.c -I/gsoap-2.8/gsoap

10、运行:./a.out

结果:

1、因为有多个ip(多个网卡)

xy@xy-pc:/workplace/mywork/onvif/gsoap-x86/mytest/myonvif/test$ ./a.out 
soap error:-10x8a29778---0x8a2977c

2、只有一个网卡,且ip所在网段正好有两个支持onvif的设备:

xy@xy-pc:/workplace/mywork/onvif/gsoap-x86/mytest/myonvif/test$ ./a.out 
=========================================
Match size:1
xsd-unsignedInt:1
scopes item:onvif://www.onvif.org/type/video_encoder onvif://www.onvif.org/type/ptz onvif://www.onvif.org/type/audio_encoder onvif://www.onvif.org/type/network_video_transmitter onvif://www.onvif.org/hardware/DM368 onvif://www.onvif.org/location/country/china onvif://www.onvif.org/name/Dahua
QName:tdn:NetworkVideoTransmitter
xsd:string:urn:uuid:5b71c61f-220b-475d-9eca-dd7941f07767
xsd:QName:0
wsa:ServiceNameType:0
sequence of elements:0
xsd:anyType:
endpoint any:0
wsdd:UriListType:http://192.168.9.110:9988/onvif/device_service
soap error:-10x87a99f8---0x87a99fc
xy@xy-pc:/workplace/mywork/onvif/gsoap-x86/mytest/myonvif/test$ 
xy@xy-pc:/workplace/mywork/onvif/gsoap-x86/mytest/myonvif/test$ 
xy@xy-pc:/workplace/mywork/onvif/gsoap-x86/mytest/myonvif/test$ ./a.out 
=========================================
Match size:1
xsd-unsignedInt:1
scopes item:onvif://www.onvif.org/type/video_encoder onvif://www.onvif.org/type/ptz onvif://www.onvif.org/type/audio_encoder onvif://www.onvif.org/type/network_video_transmitter onvif://www.onvif.org/hardware/DM368 onvif://www.onvif.org/location/country/china onvif://www.onvif.org/name/Dahua
QName:tdn:NetworkVideoTransmitter
xsd:string:urn:uuid:5b71c61f-220b-475d-9eca-dd7941f07767
xsd:QName:0
wsa:ServiceNameType:0
sequence of elements:0
xsd:anyType:
endpoint any:0
wsdd:UriListType:http://192.168.9.110:9988/onvif/device_service
soap error:-10x86929f8---0x86929fc

参考:

http://my.oschina.net/yunuo/blog/119206
http://blog.csdn.net/ghostyu/article/details/8182516

你可能感兴趣的:(SOAP,Discovery,发现,onvif)