参考资料
Onvif协议:使用gSOAP创建SOAP调用实例_gsoap 编译 soapclient soapserver-CSDN博客
一、gSOAP简单介绍
gSOAP 编译工具提供了一个SOAP关于C/C++ 语言的实现,从而让C/C++语言开发Web Services服务端或客户端程序的工作变得轻松了很多。甚至,即使你对Web Services不甚了解都没有关系,有了gSOAP这样的工具,你也能开发基于SOAP方式实现的Web Services客户端。
gSOAP到底会自动生成哪些框架代码,下图中浅绿色框中的部分就是自动生成的代码。
gSOAP工具根据WSDL文档,自动生成C/C++语言的客户端/服务端框架代码。这其中有两个工具很重要,wsdl2h和soapcpp2。wsdl2h工具根据WSDL文成C/C++头文件,而soapcpp2工具则是根据该头文件生成C/C++的框架源码。
gSOAP工具可以在Windows、Linux和Macosx操作系统下运行,gSOAP工具包中自带有Windows和Macosx操作系统的wsdl2h和soapcpp2可执行文件,而Linux操作系统的可执行文件,需要自己编译。
通过实验证实,用Windows和Linux工具生成的框架代码,是一样的,没有区别。
使用方式:
开发Web服务程序,需使用gSOAP生成服务器端和客户端代码框架(通常情况下之需要实现server端或者实现client,因为另一端通常是别人做好的,比如ipnc中的onvif,实现的server端)。我们有两种方式:
- 编写WSDL,使用wsdl2h生成头文件,再soapcpp2生成框架代码;
- 编写头文件,使用soapcpp2生成框架代码;
这两种方式,结果是一样的,最终都有产生头文件,并生成代码。不同在于,在项目的开发中需要维护的文件不同,前者是需要维护WSDL文件,后者维护头文件。本实例采用第一种方式,由于ipc网络摄像头的wsdl由onvif维护。
二、编译安装gSOAP工具
gSOAP源代码下载地址:https://sourceforge.net/projects/gsoap2/files/
shared@code-pc:/mnt/workspace/xyf$ mkdir Onvif
shared@code-pc:/mnt/workspace/xyf$ cd Onvif
shared@code-pc:/mnt/workspace/xyf/Onvif$ wget https://sourceforge.net/projects/gsoap2/files/gsoap_2.8.134.zip
我使用的版本gsoap_2.8.134
Name | Modified | Size |
---|---|---|
gsoap_2.8.134.zip | 2024-04-22 | 35.5 MB |
三、编译安装
# 1.解压
shared@code-pc:/mnt/workspace/xyf/Onvif$ unzip gsoap_2.8.134.zip -d gsoap_2.8.134
shared@code-pc:/mnt/workspace/xyf/Onvif$ cd gsoap_2.8.134/gsoap-2.8/gsoap/
# 2.配置
shared@code-pc:/mnt/workspace/xyf/Onvif/gsoap_2.8.134/gsoap-2.8$ ./configure --prefix=`pwd`/_install/x86
# 3.编译
shared@code-pc:/mnt/workspace/xyf/Onvif/gsoap_2.8.134/gsoap-2.8$ make
# 4.安装
shared@code-pc:/mnt/workspace/xyf/Onvif/gsoap_2.8.134/gsoap-2.8$ make install
知识补充:
-
语法格式:unzip <压缩文件> -d <目录>
unzip的参数-d :xtract files into exdir 解压缩文件到解压缩文件夹下
-
在运行configure时使用**–prefix选项,将软件包安装到自定义的目录/mnt/workspace/xyf/Onvif/gsoap_2.8.134/gsoap-2.8/_install/x86**
四、验证是否安装成功
# 编译结果
shared@code-pc:/mnt/workspace/xyf/Onvif/gsoap_2.8.134/gsoap-2.8$ ls _install/x86/
bin include lib share
shared@code-pc:/mnt/workspace/xyf/Onvif/gsoap_2.8.134/gsoap-2.8$ cd _install/x86/
shared@code-pc:/mnt/workspace/xyf/Onvif/gsoap_2.8.134/gsoap-2.8$ tree
.
├── bin
│ ├── soapcpp2
│ └── wsdl2h
├── include
│ └── stdsoap2.h
├── lib
│ ├── libgsoap.a
│ ├── libgsoap++.a
│ ├── libgsoapck.a
│ ├── libgsoapck++.a
│ ├── libgsoapssl.a
│ ├── libgsoapssl++.a
│ └── pkgconfig
│ ├── gsoapck.pc
│ ├── gsoapck++.pc
│ ├── gsoap.pc
│ ├── gsoap++.pc
│ ├── gsoapssl.pc
│ └── gsoapssl++.pc
└── share
└── gsoap
├── custom
│ ├── chrono_duration.cpp
│ ├── chrono_duration.h
│ ├── chrono_time_point.cpp
│ ├── chrono_time_point.h
│ ├── duration.c
│ ├── duration.h
│ ├── float128.c
│ ├── float128.h
│ ├── int128.c
│ ├── int128.h
│ ├── long_double.c
│ ├── long_double.h
│ ├── long_time.c
│ ├── long_time.h
│ ├── qbytearray_base64.cpp
│ ├── qbytearray_base64.h
│ ├── qbytearray_hex.cpp
│ ├── qbytearray_hex.h
│ ├── qdate.cpp
│ ├── qdate.h
│ ├── qdatetime.cpp
│ ├── qdatetime.h
│ ├── qstring.cpp
│ ├── qstring.h
│ ├── qtime.cpp
│ ├── qtime.h
│ ├── README.txt
│ ├── struct_timeval.c
│ ├── struct_timeval.h
│ ├── struct_tm.c
│ ├── struct_tm_date.c
│ ├── struct_tm_date.h
│ └── struct_tm.h
├── extras
│ ├── ckdb.c
│ ├── ckdb.h
│ ├── ckdbtest.c
│ ├── ckdbtest.h
│ ├── fault.cpp
│ ├── logging.cpp
│ ├── README.txt
│ └── soapdefs.h
├── import
│ ├── c14n.h
│ ├── dom.h
│ ├── ds2.h
│ ├── ds.h
│ ├── plnk.h
│ ├── README.txt
│ ├── ref.h
│ ├── saml1.h
│ ├── saml2.h
│ ├── ser.h
│ ├── soap12.h
│ ├── stdstring.h
│ ├── stldeque.h
│ ├── stl.h
│ ├── stllist.h
│ ├── stlset.h
│ ├── stlvector.h
│ ├── vprop.h
│ ├── wsa3.h
│ ├── wsa4.h
│ ├── wsa5.h
│ ├── wsa.h
│ ├── wsc2.h
│ ├── wsc.h
│ ├── wsdd10.h
│ ├── wsdd5.h
│ ├── wsdd.h
│ ├── wsdx.h
│ ├── WS-example.c
│ ├── WS-example.h
│ ├── WS-Header.h
│ ├── wsp_appliesto.h
│ ├── wsp.h
│ ├── wsrm4.h
│ ├── wsrm5.h
│ ├── wsrm.h
│ ├── wsrp.h
│ ├── wsrx5.h
│ ├── wsrx.h
│ ├── wsse11.h
│ ├── wsse2.h
│ ├── wsse.h
│ ├── wst2.h
│ ├── wst.h
│ ├── wstx2.h
│ ├── wstx.h
│ ├── wsu.h
│ ├── xenc2.h
│ ├── xenc.h
│ ├── xlink.h
│ ├── xmime4.h
│ ├── xmime5.h
│ ├── xmime.h
│ ├── xml.h
│ ├── xmlmime5.h
│ ├── xmlmime.h
│ ├── xop.h
│ └── xsd.h
├── plugin
│ ├── cacerts.c
│ ├── cacerts.h
│ ├── calcrest.h
│ ├── curlapi.c
│ ├── curlapi.h
│ ├── httpda.c
│ ├── httpda.h
│ ├── httpdatest.c
│ ├── httpdatest.h
│ ├── httpform.c
│ ├── httpform.h
│ ├── httpget.c
│ ├── httpget.h
│ ├── httpgettest.c
│ ├── httpgettest.h
│ ├── httpmd5.c
│ ├── httpmd5.h
│ ├── httpmd5test.c
│ ├── httpmd5test.h
│ ├── httppipe.c
│ ├── httppipe.h
│ ├── httppost.c
│ ├── httppost.h
│ ├── httpposttest.c
│ ├── httpposttest.h
│ ├── logging.c
│ ├── logging.h
│ ├── md5evp.c
│ ├── md5evp.h
│ ├── mecevp.c
│ ├── mecevp.h
│ ├── mq.c
│ ├── mq.h
│ ├── plugin.c
│ ├── plugin.h
│ ├── README.txt
│ ├── sessions.c
│ ├── sessions.h
│ ├── smdevp.c
│ ├── smdevp.h
│ ├── threads.c
│ ├── threads.h
│ ├── wsaapi.c
│ ├── wsaapi.h
│ ├── wsddapi.c
│ ├── wsddapi.h
│ ├── wsdl2h-httpda.o
│ ├── wsdl2h-smdevp.o
│ ├── wsdl2h-threads.o
│ ├── wsrmapi.c
│ ├── wsrmapi.h
│ ├── wsse2api.c
│ ├── wsse2api.h
│ ├── wsseapi.c
│ ├── wsseapi.cpp
│ ├── wsseapi.h
│ ├── wsseapi-lite.c
│ ├── wsseapi-lite.h
│ ├── wstapi.c
│ └── wstapi.h
└── WS
├── discovery.xsd
├── ds.xsd
├── enumeration.xsd
├── LEGAL.txt
├── oasis-sstc-saml-schema-assertion-1.1.xsd
├── README.txt
├── reference-1.1.xsd
├── saml-schema-assertion-2.0.xsd
├── typemap.dat
├── WS-Addressing03.xsd
├── WS-Addressing04.xsd
├── WS-Addressing05.xsd
├── WS-Addressing.xsd
├── ws-bpel_abstract_common_base.xsd
├── ws-bpel_executable.xsd
├── ws-bpel_plnktype.xsd
├── ws-bpel_serviceref.xsd
├── ws-bpel_varprop.xsd
├── WS-Discovery.wsdl
├── WS-Enumeration.wsdl
├── WS-Policy12.xsd
├── WS-Policy.xsd
├── ws-reliability-1.1.xsd
├── WS-ReliableMessaging.wsdl
├── WS-ReliableMessaging.xsd
├── WS-Routing.xsd
├── WS-SecureConversation.xsd
├── WS-SecurityPolicy.xsd
├── wsse.xsd
├── WS-Trust.wsdl
├── WS-Trust.xsd
├── WS-typemap.dat
├── wsu.xsd
└── xenc.xsd
11 directories, 208 files
wsdl2h工具根据WSDL文件生成C/C++头文件,而soapcpp2工具则是根据该头文件生成C/C++的框架源码。
shared@code-pc:/mnt/workspace/xyf/Onvif/gsoap_2.8.134/gsoap-2.8/_install/x86$ ls
bin include lib share
shared@code-pc:/mnt/workspace/xyf/Onvif/gsoap_2.8.134/gsoap-2.8/_install/x86$ cd bin/
shared@code-pc:/mnt/workspace/xyf/Onvif/gsoap_2.8.134/gsoap-2.8/_install/x86/bin$ ls
soapcpp2 wsdl2h
shared@code-pc:/mnt/workspace/xyf/Onvif/gsoap_2.8.134/gsoap-2.8/_install/x86/bin$ ./soapcpp2 -h
Usage: soapcpp2 [-0|-1|-2] [-C|-S|-CS] [-A] [-a] [-b] [-c|-c++|-c++11|-c++14|-c++17] [-d path] [-Ec] [-Ed] [-Et] [-e] [-f N] [-g] [-h] [-i] [-I path:path:...] [-L] [-l] [-m] [-n] [-p name] [-Q name] [-q name] [-r] [-s] [-T] [-t] [-u] [-V] [-v] [-w] [-x] [-y] [-z#] [infile]
-0 no SOAP, generate REST source code
-1 generate SOAP 1.1 source code
-2 generate SOAP 1.2 source code
-A require HTTP SOAPAction headers to invoke server-side operations
-a use HTTP SOAPAction with WS-Addressing to invoke server-side operations
-b serialize byte arrays char[N] as string
-C generate client-side source code only
-c generate C source code
-c++ generate C++ source code (default)
-c++11 generate C++ source code optimized for C++11 (compile with -std=c++11)
-c++14 generate C++ source code optimized for C++14 (compile with -std=c++14)
-c++17 generate C++ source code optimized for C++17 (compile with -std=c++17)
-dpath use path to save files
-Ec generate extra functions for deep copying
-Ed generate extra functions for deep deletion
-Et generate extra functions for data traversals with callback functions
-e generate SOAP RPC encoding style bindings (also use -1 or -2)
-fN multiple soapC files, with N serializer definitions per file (N>=10)
-g generate XML sample messages in template format for testmsgr
-h display help info and exit
-Ipath use path(s) for #import (paths separated with ':')
-i generate C++ service proxies and objects inherited from soap struct
-j generate C++ service proxies and objects that share a soap struct
-L don't generate soapClientLib/soapServerLib
-l generate linkable modules (experimental)
-m generate source code for the Matlab(tm) MEX compiler (deprecated)
-n use service name to rename service functions and namespace table
-pname save files with new prefix name instead of 'soap'
-Qname use name as the C++ namespace, including custom serializers
-qname use name as the C++ namespace, excluding custom serializers
-r generate soapReadme.md report
-S generate server-side source code only
-s generate stub and skeleton functions with strict XML validation checks
-T generate server auto-test source code
-t generate source code for fully xsi:type typed SOAP/XML messages
-u uncomment WSDL/schema output by suppressing XML comments
-V display the current version and exit
-v verbose output
-w don't generate WSDL and schema files
-x don't generate sample XML message files
-y include C/C++ type access information in sample XML messages
-z1 compatibility: generate old-style C++ service proxies and objects
-z2 compatibility with 2.7.x: omit XML output for NULL pointers
-z3 compatibility up to 2.8.30: _param_N indexing and nillable pointers
-z4 compatibility up to 2.8.105: char* member defaults, even when omitted
infile header file to parse (if none reads stdin)
shared@code-pc:/mnt/workspace/xyf/Onvif/gsoap_2.8.134/gsoap-2.8/_install/x86/bin$ ./wsdl2h -h
Usage: wsdl2h [-a] [-b] [-c|-c++|-c++11|-c++14|-c++17] [-D] [-d] [-e] [-F] [-f] [-g] [-h] [-I path] [-i] [-j] [-k] [-L] [-l] [-M] [-m] [-N name] [-n name] [-O1|-O2|-O3|-O4|-Ow2|-Ow3|-Ow4] [-P|-p] [-Q] [-q name] [-R] [-r proxyhost[:port[:uid:pwd]]] [-r:uid:pwd] [-Sname] [-s] [-T] [-t typemapfile] [-U] [-u] [-V] [-v] [-w] [-W] [-x] [-y] [-z#] [-_] [-o outfile.h] infile.wsdl infile.xsd http://www... ...
-a generate indexed struct names for local elements with anonymous types
-b bi-directional operations (duplex ops) added to serve one-way responses
-c generate C source code
-c++ generate C++ source code (default)
-c++11 generate C++11 source code
-c++14 generate C++14 source code
-c++17 generate C++17 source code
-D make attribute members with default/fixed values optional with pointers
-d use DOM to populate xs:any, xs:anyType, and xs:anyAttribute
-e don't qualify enum names
-F add transient members to structs to simulate struct-type derivation in C
-f generate flat C++ class hierarchy by removing inheritance
-g generate global top-level element and attribute declarations
-h display help info and exit
-Ipath use path to locate WSDL and XSD 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 generate less documentation by removing generic @note comments
-l display license information
-M suppress error "must understand element with wsdl:required='true'"
-m use xsd.h module to import primitive types
-Nname use name for service prefixes to produce a service for each binding
-nname use name as the base namespace prefix instead of 'ns'
-O1 optimize by omitting duplicate choice/sequence members
-O2 optimize -O1 and omit unused schema types (unreachable from roots)
-O3 optimize -O2 and omit unused schema root attributes
-O4 optimize -O3 and omit unused schema root elements (use only with WSDLs)
-Ow2 optimize -O2 while retaining all derived types of used base types
-Ow3 optimize -O3 while retaining all derived types of used base types
-Ow4 optimize -O4 while retaining all derived types of used base types
-ofile output to file
-P don't create polymorphic types inherited from xsd__anyType
-p create polymorphic types inherited from base xsd__anyType
-Q make xsd__anySimpleType equal to xsd__anyType to use as the base type
-qname use name for the C++ namespace of all declarations
-R generate REST operations for REST bindings specified in a WSDL
-rhost[:port[:uid:pwd]]
connect via proxy host, port, and proxy credentials uid and pwd
-r:uid:pwd
connect with authentication credentials uid and pwd
-Sname use name instead of 'soap' for the C++ class members with soap contexts
-s don't generate STL code (no std::string and no std::vector)
-tfile use type map file instead of the default file typemap.dat
-U allow UTF-8-encoded Unicode C/C++ identifiers when mapping XML tag names
-u don't generate unions
-V display the current version and exit
-v verbose output
-W suppress warnings
-w always wrap response parameters in a response struct (<=1.1.4 behavior)
-X don't qualify part names to disambiguate doc/lit wrapped patterns
-x don't generate _XML any/anyAttribute extensibility elements
-y generate typedef synonyms for structs and enums
-z1 compatibility with 2.7.6e: generate pointer-based arrays
-z2 compatibility with 2.7.7-2.7.15: (un)qualify element/attribute refs
-z3 compatibility with 2.7.16-2.8.7: (un)qualify element/attribute refs
-z4 compatibility up to 2.8.11: don't generate union structs in std::vector
-z5 compatibility up to 2.8.15: don't include minor improvements
-z6 compatibility up to 2.8.17: don't include minor improvements
-z7 compatibility up to 2.8.59: don't generate std::vector of class of union
-z8 compatibility up to 2.8.74: don't gen quals for doc/lit wrapped patterns
-z9 compatibility up to 2.8.93: always qualify element/attribute refs
-z10 compatibility up to 2.8.96: gen quals even when defined w/o namespace
-_ don't generate _USCORE (replace with Unicode code point _x005f)
infile.wsdl infile.xsd http://www... list of input sources (if none reads stdin)
2.8.59: don't generate std::vector of class of union
-z8 compatibility up to 2.8.74: don't gen quals for doc/lit wrapped patterns
-z9 compatibility up to 2.8.93: always qualify element/attribute refs
-z10 compatibility up to 2.8.96: gen quals even when defined w/o namespace
-_ don't generate _USCORE (replace with Unicode code point _x005f)
infile.wsdl infile.xsd http://www... list of input sources (if none reads stdin)