windows用gsoap onvif wsdl转.h cpp

1.下载gsoap      

https://sourceforge.net/projects/gsoap2https://sourceforge.net/projects/gsoap2/

2.下载wsdl文件
Home - ONVIF Mandarinhttps://www.onvif.org/profiles/specifications/ 

3. 初始化工作目录

(0)gsoap-2.8是下载好解压出来的

(1)新建wsdl文件夹, 里面是刚下载好的wsdl和xsd文件

(2) soapcpp2.exe和wsdl2h是从"F:\study\onvif\gsoap-2.8\gsoap\bin\win32\" 拷贝出来的

(3)typemap.dat是从"F:\study\onvif\gsoap-2.8\gsoap\"拷贝出来的

(4)bin文件夹是从"F:\study\onvif\gsoap-2.8\gsoap\" 拷贝出来的

4.生成onvif.h文件

(1) wsdl文件夹中的所有文件, 把引用xsd的路径修改一下.

 (2) 命令行

  wsdl2h -t typemap.dat -o onvif.h ./wsdl/accesscontrol.wsdl ./wsdl/accessrules.wsdl ./wsdl/actionengine.wsdl ./wsdl/advancedsecurity.wsdl ./wsdl/analytics.wsdl ./wsdl/appmgmt.wsdl ./wsdl/authenticationbehavior.wsdl ./wsdl/credential.wsdl ./wsdl/deviceio.wsdl ./wsdl/devicemgmt.wsdl ./wsdl/display.wsdl ./wsdl/doorcontrol.wsdl ./wsdl/event.wsdl ./wsdl/imaging.wsdl ./wsdl/media.wsdl ./wsdl/media2.wsdl ./wsdl/provisioning.wsdl ./wsdl/ptz.wsdl ./wsdl/receiver.wsdl ./wsdl/recording.wsdl ./wsdl/replay.wsdl ./wsdl/schedule.wsdl ./wsdl/search.wsdl ./wsdl/thermal.wsdl ./wsdl/uplink.wsdl

参数解析

-c : 生成c风格代码(注:后缀名还是.cpp ,但实际上是.c)
-c++:生成c++风格代码(注 : 默认是生成c++代码)
-x : 表示不生成xml 文件(注:生成的xml文件,有助于了解发送是SOAP是怎样的结构,建议不使用-x)
-l : 表示指定导入路径
-s : 不使用STL代码
-o: 生成.h文件叫什么名字
-t : 后面紧跟“typemap.dat”这个批处理文件


 -a      generate indexed struct names for local elements with anonymous types
 -b bir-directional operations (duplex ops) to serve onerem -way response messages
 -c      生成c源代码(默认为生成C++头文件)  generate C source code
 -d      use DOM to populate xs:any, xs:anyType, and xs:anyAttribute
 -e      don't qualify enum names
 -f      生成平面的C++类层次结构(没有看到现象)  generate flat C++ class hierarchy
 -g      generate global top-level element declarations
 -h      display help info
 -Ipath  查找文件路径  use path to find files
 -i      don't import (advanced option)
 -j      don't generate SOAP_ENV__Header and SOAP_ENV__Detail definitions
 -k      don't generate SOAP_ENV__Header mustUnderstand qualifiers
 -l      display license information
 -m      use xsd.h module to import primitive types
 -Nname  use name for service namespace prefixes and multiple bindings
 -nname  使用"name"基础命名空间前缀代替"ns"  use name as the base namespace prefix instead of 'ns'
 -ofile  指定输出文件  output to file
 -P      don't create polymorphic types inherited from xsd__anyType
 -p      create polymorphic types inherited from base xsd__anyType
 -qname  在所有声明中使用命名空间"name"(同时拥有-p功能)  use name for the C++ namespace of all declarations
 -rhost  [:port[:uid:pwd]]connect via proxy host, port, and proxy credentials
 -s      不使用Std代码  don't generate STL code (no std::string and no std::vector)
 -tfile  use type map file instead of the default file typemap.dat—— 
typemap.dat包含信息,如SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"xsi="http://www.w3.org/2001/XMLSchema-instance"xsd="http://www.w3.org/2001/XMLSchema"
 -u      don't generate unions
 -v      verbose output
 -W      suppress warnings
 -w      always wrap response parameters in a response struct (<=1.1.4 behavior)
 -x      don't generate _XML any/anyAttribute extensibility elements
 -y      generate typedef synonyms for structs and enums
 -z1     compatibility with 2.7.6e: generate pointerrem -based arrays
 -z2     compatibility with 2.7.7 to 2.7.15: qualify element/attribute references
 -z3     compatibility with 2.7.16 to 2.8.7: qualify element/attribute references
 -z4     compatibility up to 2.8.11: don't generate union structs in std::vector
 -_      don't generate _USCORE (replace with UNICODE _x005f)infile.wsdl infile.xsd http://www... list of input sources (if none: use stdin)

(3) 执行截图

 cmd 切换目录到 F:\study\onvif\  然后开始执行. 会报xsd或者wsdl找不到, 就用第(1)条方法去修改.

 执行成功了

F:\study\onvif\ 下面有个onvif.h

5.生成源码

在项目开发过程中,往往需要使用“鉴权”这项功能(访问或修改设备参数,需要用户名跟密码,在数据传输过程中,密码是进行了加密处理的),所以在正式生成代码之前在onvif.h文件中加上下面的代码:

#import "wsse.h"

soapcpp2 -j -2 -x onvif.h -I./gsoap-2.8/gsoap/import -I./gsoap-2.8/gsoap/

soapcpp2 -i -2 -x onvif.h -I./gsoap-2.8/gsoap/import -I./gsoap-2.8/gsoap/

-c : 生成c风格的代码,因为默认是c++风格的代码
-2:采用SOAP1.2,和SOAP1.0版本不同,会导致搜索工具搜索不到
-I : 指定路径
-x : 不产生xml 文件(不建议是用该选项,xml在开发中具有参考意义)

-1      使用SOAP 1.1进行编译
-2      使用SOAP 1.1进行编译
-C      只生成客户端代码
-S      只生成服务端代码
-T      generate server autorem -test code
-L      不生成soapClientLib/soapServerLib文件(使用-i就有-L的功能,理解为将ClientLib和Client变对象)
-a      use SOAPAction HTTP/WSA header to invoke serverrem -side operations
-b      serialize byte arrays char[N] as string
-c      生成c源代码(没有现象)  generate C source code
-dpath  生成代码路径
-e      generate SOAP RPC encoding style bindings
-fN     file split of N XML serializer implementations per file (N>=10)
-h      display help info
-Ipath  代码导入路径
-i      从SOAP结构继承,生成C++服务代理和对象
-j      通过共享SOAP结构,生成C++服务代理和对象
-k      generate data structure walkers (experimental)
-l      generate linkable modules (experimental)
-m      generate Matlab(tm) code for MEX compiler
-n      use service name to rename service functions and namespace table
-pname  使用新前缀"name"代替"soap"        save files with new prefix name instead of 'soap'
-qname  在所有声明中使用命名空间"name"(同时拥有-p功能)
-s      生成具有严格的XML验证检查反序列化代码  generate deserialization code with strict XML validation checks
-t      生成代码全部使用xsi:type类型soap/XML消息。  generate code for fully xsi:type typed SOAP/XML messaging
-u      uncomment comments in WSDL/schema output by suppressing XML comments
-v      显示版本信息(没有看到现象--生成代码没有变化)
-w      不生成WSDL和模式文件
-x      不生成XML文件
-y      包括C / C++类型访问信息的示例XML消息(没有看到现象)

 

成功了

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值