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 中添加:

[cpp]  view plain copy
  1. #Use gSOAP 2.8.10 and up. In the typemap.dat file used by wsdl2h, add:  
  2. #   ONVIF recommended prefixes  
  3. tds = "http://www.onvif.org/ver10/device/wsdl"  
  4. tev = "http://www.onvif.org/ver10/events/wsdl"  
  5. tls = "http://www.onvif.org/ver10/display/wsdl"  
  6. tmd = "http://www.onvif.org/ver10/deviceIO/wsdl"  
  7. timg    = "http://www.onvif.org/ver20/imaging/wsdl"  
  8. trt = "http://www.onvif.org/ver10/media/wsdl"  
  9. tptz    = "http://www.onvif.org/ver20/ptz/wsdl"  
  10. trv = "http://www.onvif.org/ver10/receiver/wsdl"  
  11. trc = "http://www.onvif.org/ver10/recording/wsdl"  
  12. tse = "http://www.onvif.org/ver10/search/wsdl"  
  13. trp = "http://www.onvif.org/ver10/replay/wsdl"  
  14. tan = "http://www.onvif.org/ver20/analytics/wsdl"  
  15. tad = "http://www.onvif.org/ver10/analyticsdevice/wsdl"  
  16. tdn = "http://www.onvif.org/ver10/network/wsdl"  
  17. tt  = "http://www.onvif.org/ver10/schema"  
  18. #   OASIS recommended prefixes  
  19. wsnt    = "http://docs.oasis-open.org/wsn/b-2"  
  20. wsntw   = "http://docs.oasis-open.org/wsn/bw-2"  
  21. wsrfbf  = "http://docs.oasis-open.org/wsrf/bf-2"  
  22. wsrfr   = "http://docs.oasis-open.org/wsrf/r-2"  
  23. wsrfrw  = "http://docs.oasis-open.org/wsrf/rw-2"  
  24. wstop   = "http://docs.oasis-open.org/wsn/t-1"  
  25. #   WS-Discovery 1.0 remapping  
  26. wsdd10__HelloType       = | wsdd__HelloType  
  27. wsdd10__ByeType         = | wsdd__ByeType  
  28. wsdd10__ProbeType       = | wsdd__ProbeType  
  29. wsdd10__ProbeMatchesType    = | wsdd__ProbeMatchesType  
  30. wsdd10__ProbeMatchType      = | wsdd__ProbeMatchType  
  31. wsdd10__ResolveType     = | wsdd__ResolveType  
  32. wsdd10__ResolveMatchesType  = | wsdd__ResolveMatchesType  
  33. wsdd10__ResolveMatchType    = | wsdd__ResolveMatchType  
  34. #   SOAP-ENV mapping  
  35. SOAP_ENV__Envelope  = struct SOAP_ENV__Envelope { struct SOAP_ENV__Header *SOAP_ENV__Header; _XML SOAP_ENV__Body; }; | struct SOAP_ENV__Envelope  
  36. SOAP_ENV__Header    = | struct SOAP_ENV__Header  
  37. SOAP_ENV__Fault     = | struct SOAP_ENV__Fault  
  38. SOAP_ENV__Detail    = | struct SOAP_ENV__Detail  
  39. SOAP_ENV__Code      = | struct SOAP_ENV__Code  
  40. SOAP_ENV__Subcode   = | struct SOAP_ENV__Subcode  
  41. 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、测试代码:

[cpp]  view plain copy
  1. #include <iostream>  
  2. #include "wsdd.nsmap"  
  3. #include "soapH.h"  
  4. using namespace std;  
  5. int main()  
  6. {  
  7.     struct soap *soap;  
  8.     struct wsdd__ProbeType req;  
  9.     struct __wsdd__ProbeMatches resp;  
  10.     struct wsdd__ScopesType sScope;  
  11.     struct SOAP_ENV__Header header;  
  12.     int count = 0;  
  13.     int result = 0;   
  14.   
  15.     char guid_string[100];  
  16.   
  17.      soap = soap_new();   
  18.     if(soap==NULL)  
  19.     {  
  20.         return -1;  
  21.     }  
  22.    
  23.     soap_set_namespaces(soap, namespaces);   
  24.   
  25.     soap->recv_timeout = 5;      //超过5秒钟没有数据就退出  
  26.     soap_default_SOAP_ENV__Header(soap, &header);  
  27.    
  28.     header.wsa__MessageID = guid_string;  
  29.     header.wsa__To= "urn:schemas-xmlsoap-org:ws:2005:04:discovery";  
  30.     header.wsa__Action= "http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe";  
  31.     soap->header = &header;  
  32.   
  33.     soap_default_wsdd__ScopesType(soap, &sScope);  
  34.     sScope.__item = "";  
  35.     soap_default_wsdd__ProbeType(soap, &req);  
  36.     req.Scopes = &sScope;  
  37.     req.Types = "";  
  38.   
  39.     result = soap_send___wsdd__Probe(soap, "soap.udp://239.255.255.250:3702", NULL, &req);  
  40.   
  41.     do{  
  42.          result = soap_recv___wsdd__ProbeMatches(soap, &resp);   
  43.          if (soap->error)   
  44.          {   
  45.              cout<<"soap error:"<<soap->error<<soap_faultcode(soap)<<"---"<<soap_faultstring(soap)<<endl;   
  46.              result = soap->error;   
  47.              break;  
  48.          }   
  49.          else  
  50.          {  
  51.             cout<<"========================================="<<endl;  
  52.    
  53.             cout<<"Match size:"<<resp.wsdd__ProbeMatches->__sizeProbeMatch<<endl;  
  54.             cout<<"xsd-unsignedInt:"<<resp.wsdd__ProbeMatches->ProbeMatch->MetadataVersion<<endl;  
  55.             cout<<"scopes item:"<<resp.wsdd__ProbeMatches->ProbeMatch->Scopes->__item<<endl;  
  56.             //cout<<"scopes matchby:"<<resp.wsdd__ProbeMatches->ProbeMatch->Scopes->MatchBy<<endl;  
  57.             cout<<"QName:"<<resp.wsdd__ProbeMatches->ProbeMatch->Types<<endl;  
  58.             cout<<"xsd:string:"<<resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.Address<<endl;  
  59.             cout<<"xsd:QName:"<<resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.PortType<<endl;  
  60.             cout<<"wsa:ServiceNameType:"<<resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.ServiceName<<endl;  
  61.             cout<<"sequence of elements:"<<resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.__size<<endl;  
  62.             cout<<"xsd:anyType:"<<resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.__anyAttribute<<endl;  
  63.             cout<<"endpoint any:"<<resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.__any<<endl;  
  64.             cout<<"wsdd:UriListType:"<<resp.wsdd__ProbeMatches->ProbeMatch->XAddrs<<endl;  
  65.          }  
  66.      }while(1);  
  67.   
  68.     soap_destroy(soap); // remove deserialized class instances (C++ only)   
  69.     soap_end(soap);     // clean up and remove deserialized data  
  70.     soap_done(soap);  
  71.   
  72.     return result;  
  73. }  

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

10、运行:./a.out

结果:

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

[cpp]  view plain copy
  1. xy@xy-pc:/workplace/mywork/onvif/gsoap-x86/mytest/myonvif/test$ ./a.out   
  2. soap error:-10x8a29778---0x8a2977c  

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

[cpp]  view plain copy
  1. xy@xy-pc:/workplace/mywork/onvif/gsoap-x86/mytest/myonvif/test$ ./a.out   
  2. =========================================  
  3. Match size:1  
  4. xsd-unsignedInt:1  
  5. 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  
  6. QName:tdn:NetworkVideoTransmitter  
  7. xsd:string:urn:uuid:5b71c61f-220b-475d-9eca-dd7941f07767  
  8. xsd:QName:0  
  9. wsa:ServiceNameType:0  
  10. sequence of elements:0  
  11. xsd:anyType:  
  12. endpoint any:0  
  13. wsdd:UriListType:http://192.168.9.110:9988/onvif/device_service  
  14. soap error:-10x87a99f8---0x87a99fc  
  15. xy@xy-pc:/workplace/mywork/onvif/gsoap-x86/mytest/myonvif/test$   
  16. xy@xy-pc:/workplace/mywork/onvif/gsoap-x86/mytest/myonvif/test$   
  17. xy@xy-pc:/workplace/mywork/onvif/gsoap-x86/mytest/myonvif/test$ ./a.out   
  18. =========================================  
  19. Match size:1  
  20. xsd-unsignedInt:1  
  21. 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  
  22. QName:tdn:NetworkVideoTransmitter  
  23. xsd:string:urn:uuid:5b71c61f-220b-475d-9eca-dd7941f07767  
  24. xsd:QName:0  
  25. wsa:ServiceNameType:0  
  26. sequence of elements:0  
  27. xsd:anyType:  
  28. endpoint any:0  
  29. wsdd:UriListType:http://192.168.9.110:9988/onvif/device_service  
  30. soap error:-10x86929f8---0x86929fc  

参考:

http://my.oschina.net/yunuo/blog/119206
/link.php?url=http://blog.csdn.net/ghostyu/article/details/8182516

作者:xyyangkun 发表于2013-6-18 17:37:39  原文链接
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值