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 plaincopy
  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
[cpp] view plaincopy
  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 plaincopy
  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. char guid_string[100];
  15. soap = soap_new();
  16. if(soap==NULL)
  17. {
  18. return -1;
  19. }
  20. soap_set_namespaces(soap, namespaces);
  21. soap->recv_timeout = 5;      //超过5秒钟没有数据就退出
  22. soap_default_SOAP_ENV__Header(soap, &header);
  23. header.wsa__MessageID = guid_string;
  24. header.wsa__To= "urn:schemas-xmlsoap-org:ws:2005:04:discovery";
  25. header.wsa__Action= "http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe";
  26. soap->header = &header;
  27. soap_default_wsdd__ScopesType(soap, &sScope);
  28. sScope.__item = "";
  29. soap_default_wsdd__ProbeType(soap, &req);
  30. req.Scopes = &sScope;
  31. req.Types = "";
  32. result = soap_send___wsdd__Probe(soap, "soap.udp://239.255.255.250:3702", NULL, &req);
  33. do{
  34. result = soap_recv___wsdd__ProbeMatches(soap, &resp);
  35. if (soap->error)
  36. {
  37. cout<<"soap error:"<<soap->error<<soap_faultcode(soap)<<"---"<<soap_faultstring(soap)<<endl;
  38. result = soap->error;
  39. break;
  40. }
  41. else
  42. {
  43. cout<<"========================================="<<endl;
  44. cout<<"Match size:"<<resp.wsdd__ProbeMatches->__sizeProbeMatch<<endl;
  45. cout<<"xsd-unsignedInt:"<<resp.wsdd__ProbeMatches->ProbeMatch->MetadataVersion<<endl;
  46. cout<<"scopes item:"<<resp.wsdd__ProbeMatches->ProbeMatch->Scopes->__item<<endl;
  47. //cout<<"scopes matchby:"<<resp.wsdd__ProbeMatches->ProbeMatch->Scopes->MatchBy<<endl;
  48. cout<<"QName:"<<resp.wsdd__ProbeMatches->ProbeMatch->Types<<endl;
  49. cout<<"xsd:string:"<<resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.Address<<endl;
  50. cout<<"xsd:QName:"<<resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.PortType<<endl;
  51. cout<<"wsa:ServiceNameType:"<<resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.ServiceName<<endl;
  52. cout<<"sequence of elements:"<<resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.__size<<endl;
  53. cout<<"xsd:anyType:"<<resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.__anyAttribute<<endl;
  54. cout<<"endpoint any:"<<resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.__any<<endl;
  55. cout<<"wsdd:UriListType:"<<resp.wsdd__ProbeMatches->ProbeMatch->XAddrs<<endl;
  56. }
  57. }while(1);
  58. soap_destroy(soap); // remove deserialized class instances (C++ only)
  59. soap_end(soap);     // clean up and remove deserialized data
  60. soap_done(soap);
  61. return result;
  62. }
[cpp] view plaincopy
  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. char guid_string[100];
  15. soap = soap_new();
  16. if(soap==NULL)
  17. {
  18. return -1;
  19. }
  20. soap_set_namespaces(soap, namespaces);
  21. soap->recv_timeout = 5;      //超过5秒钟没有数据就退出
  22. soap_default_SOAP_ENV__Header(soap, &header);
  23. header.wsa__MessageID = guid_string;
  24. header.wsa__To= "urn:schemas-xmlsoap-org:ws:2005:04:discovery";
  25. header.wsa__Action= "http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe";
  26. soap->header = &header;
  27. soap_default_wsdd__ScopesType(soap, &sScope);
  28. sScope.__item = "";
  29. soap_default_wsdd__ProbeType(soap, &req);
  30. req.Scopes = &sScope;
  31. req.Types = "";
  32. result = soap_send___wsdd__Probe(soap, "soap.udp://239.255.255.250:3702", NULL, &req);
  33. do{
  34. result = soap_recv___wsdd__ProbeMatches(soap, &resp);
  35. if (soap->error)
  36. {
  37. cout<<"soap error:"<<soap->error<<soap_faultcode(soap)<<"---"<<soap_faultstring(soap)<<endl;
  38. result = soap->error;
  39. break;
  40. }
  41. else
  42. {
  43. cout<<"========================================="<<endl;
  44. cout<<"Match size:"<<resp.wsdd__ProbeMatches->__sizeProbeMatch<<endl;
  45. cout<<"xsd-unsignedInt:"<<resp.wsdd__ProbeMatches->ProbeMatch->MetadataVersion<<endl;
  46. cout<<"scopes item:"<<resp.wsdd__ProbeMatches->ProbeMatch->Scopes->__item<<endl;
  47. //cout<<"scopes matchby:"<<resp.wsdd__ProbeMatches->ProbeMatch->Scopes->MatchBy<<endl;
  48. cout<<"QName:"<<resp.wsdd__ProbeMatches->ProbeMatch->Types<<endl;
  49. cout<<"xsd:string:"<<resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.Address<<endl;
  50. cout<<"xsd:QName:"<<resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.PortType<<endl;
  51. cout<<"wsa:ServiceNameType:"<<resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.ServiceName<<endl;
  52. cout<<"sequence of elements:"<<resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.__size<<endl;
  53. cout<<"xsd:anyType:"<<resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.__anyAttribute<<endl;
  54. cout<<"endpoint any:"<<resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.__any<<endl;
  55. cout<<"wsdd:UriListType:"<<resp.wsdd__ProbeMatches->ProbeMatch->XAddrs<<endl;
  56. }
  57. }while(1);
  58. soap_destroy(soap); // remove deserialized class instances (C++ only)
  59. soap_end(soap);     // clean up and remove deserialized data
  60. soap_done(soap);
  61. return result;
  62. }

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

10、运行:./a.out

结果:

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

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

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

[cpp] view plaincopy
  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
[cpp] view plaincopy
  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
http://blog.csdn.net/ghostyu/article/details/8182516

onvif 客户端发现相关推荐

  1. onvif学习笔记8:最近写的一个ONVIF客户端的心得小结

    最近,利用业余时间编写一个简单的ONVIF客户端MFC程序,这里记录一下过程. 语言选择 在之前调查过,有用QT实现的,有用python实现的,虽然正在学python,无奈才看了3天的书,没自信去搞. ...

  2. ONVIF客户端搜索设备获取rtsp地址开发笔记(精华篇)

    概要:   目前ONVIF协议家族设备已占据数字监控行业半壁江山以上,亲,作为开发者的你还在犹豫是否了解下吗?本文介绍了ONVIF客户端从设备搜索,鉴权,能力获取,媒体信息获取,URI地址获取的整套流 ...

  3. 【视频开发】ONVIF客户端搜索设备获取rtsp地址开发笔记(精华篇)

    转载地址:http://blog.csdn.net/gubenpeiyuan/article/details/25618177 概要:           目前ONVIF协议家族设备已占据数字监控行业 ...

  4. onvif客户端(转载)

    本文为转载文章,文章出处为:https://www.cnblogs.com/rongpmcu/p/10351204.html 如果有侵权请及时联系删除,如想转载请先去联系原作者 onvif客户端 前言 ...

  5. 关于 客户端发现响应内容类型为“text/html; charset=utf-8”,但应为“text/xml”的解决方法...

    关于 客户端发现响应内容类型为"text/html; charset=utf-8",但应为"text/xml"的解决方法 请求web服务时,会有如题的异常出现, ...

  6. SCCM 2012 R2---配置客户端发现方法和边界组

    二.安装SCCM 2012 R2客户端 1.配置SCCM 2012 R2客户端发现方法 安装完成后我们打开SCCM 2012 R2的控制台: 点击左侧栏的"管理"选项,然后展开&q ...

  7. SCCM2012之客户端发现与安装

    通过前面两次实验,我们已经完成了SCCM 2012的安装,下面就开始进入SCCM 2012的管理与使用.进入管理控制台,我们可以发现SCCM 2012管理控制台与前作发生了很大的变化,整个界面添加了如 ...

  8. SCCM2012SP1---配置客户端发现方法和边界组

    二.安装SCCM客户端 1.配置SCCM 2012客户端发现方法 安装完成后我们打开SCCM 2012的控制台: 点击左侧栏的"管理"选项,然后展开"层次结构配置&quo ...

  9. SCCM2012R2部署之四:配置客户端发现

    前面3个章节我们简单的,介绍了安装配置和相关的组件.接下来我们需要给大家介绍的是如何配置客户端发现,让SCCM能真正管控到AD中的所有终端,来提供IT运维的效率. 首先我们打开SCCM控制台,如图4- ...

最新文章

  1. 本人在学习PHP过程中的随笔心得
  2. GIT:本地有更改,但强制作远程仓库里作更新
  3. 444牛X的日常口语
  4. 可遇不可求的BUG之采用MYSQL odbc 3.51访问数据库返回值缺失
  5. python简单代码input-python基础 input()函数
  6. 详细学习ORACLE JOBS
  7. EF6 CodeFirst+Repository+Ninject+MVC4+EasyUI实践(六)
  8. 线程间操作无效: 从不是创建控件“progressBar1”的线程访问它。
  9. 若5G的速度不够:那6G和16K是必然么?
  10. CentOS安装scp命令
  11. 公共技术点之 Java 注解 Annotation
  12. c#获取本地ip地址网关子网掩码_C#--WinForm获取本机网卡的型号,IP地址,子网掩码和网关-阿里云开发者社区...
  13. spark-08-SparkStraming简介与kafka0.8集群安装
  14. LeetCode 84. Largest Rectangle in Histogram
  15. android手机上传不了图片,【报Bug】nvue页面使用web-view组件,安卓手机无法调用页面的input标签上传图片...
  16. Delphi之TClientSocket和TServerSocket使用tcp keepalive心跳机制实现“断网”、断电检测...
  17. 需要什么数据?要说清楚、准确
  18. 制作一个模拟Windows启动界面的文本进度条python
  19. 梯度消失和爆炸原因以及解决方法
  20. python实现电子邮件编程

热门文章

  1. PreparedStatement批量执行sql
  2. Java并发之Condition的实现分析
  3. Spring Cloud 微服务入门(一)--初识分布式及其发展历程
  4. LAMP+LNMP(一) LAMP架构概述
  5. WF4 AttachedPropertiesService
  6. Linux workqueue疑问【转】
  7. Java输出特定时间段特定格式时间信息
  8. android初学之sharedpreferences存储
  9. 存储专家论IP存储现实可行性
  10. SQL Server之备份和还原系统数据库