如果说,我们自己去解析WSDL,组装成SOAP消息,再通过HTTP+SOAP的方式跟服务器通信,那将是一个比较繁琐的工作。这篇文章介绍一个第三方开源库 gSoap ,它帮我们做了 Web Services 架构相关的很多工作,使Onvif相关的开发工作变得简单很多。下面先了解一下gSoap,然后介绍怎样使用这个库生成 Onvif 框架代码。
🎄二、简单了解 gSoap
gSOAP 工具套件(toolkit)是一套广泛的可移植C和C++软件,用于开发具有强大的类型安全XML数据绑定的XML Web服务。易于使用的代码生成器工具允许您在C和C++中直接集成XML数据。用XML序列化本机应用程序数据。包括WSDL/XSD模式绑定和自动编码工具、存根/框架编译器、与Apache模块和IIS扩展的Web服务器集成、带模式验证的高性能XML处理、快速MIME/MTOM流、SOAP和REST Web API开发、WS-*协议(WS-Security、WS-Policy、WS-ReliableMessaging等)、XML-RPC和JSON。GPLv2许可。
unzip gsoap_2.8.139.zip
cd gsoap-2.8/
./configure --prefix=`pwd`/../result_gcc --with-openssl=`pwd`/../openssl-1.1.1w_result_gcc --with-zlib=`pwd`/../zlib_result_gcc
make && make install
(CDPATH="${ZSH_VERSION+.}:" && cd . && /bin/bash '/home/samba/opensource/20_gsoap/gsoap-2.8/missing' autoheader)
/home/samba/opensource/20_gsoap/gsoap-2.8/missing: 行 81: autoheader: 未找到命令
WARNING: 'autoheader' is missing on your system.
You should only need it if you modified 'acconfig.h' or
'configure.ac' or m4 files included by 'configure.ac'.
The 'autoheader' program is part of the GNU Autoconf package:
<https://www.gnu.org/software/autoconf/>
It also requires GNU m4 and Perl in order to run:
<https://www.gnu.org/software/m4/>
<https://www.perl.org/>
Makefile:426: recipe for target 'config.h.in' failed
make: *** [config.h.in] Error 127
$ ../../result_gcc/bin/soapcpp2 -2 -C -L -c -x -I import:custom -d samples/onvif/ samples/onvif/onvif.h
** The gSOAP code generator for C and C++, soapcpp2 release 2.8.139
** Copyright (C) 2000-2025 Genivia Inc. All Rights Reserved.
** The soapcpp2 tool and its generated software are released under the GPL.
** ----------------------------------------------------------------------------
** A commercial use license is available from Genivia Inc., contact@genivia.com
** ----------------------------------------------------------------------------
soap12.h(54): *WARNING*: option -1 or -2 overrides SOAP-ENV namespace
soap12.h(55): *WARNING*: option -1 or -2 overrides SOAP-ENC namespace
Using project directory path: samples/onvif/
Saving samples/onvif/soapStub.h annotated copy of the source interface header file
Saving samples/onvif/soapH.h serialization functions to #include in projects
Using wsdd service name: wsdd
Using wsdd service style: document
Using wsdd service encoding: literal
Using wsdd schema import namespace: http://schemas.xmlsoap.org/ws/2005/04/discovery
Saving samples/onvif/wsdd.nsmap namespace mapping table
Using tdn service name: RemoteDiscoveryBinding
Using tdn service style: document
Using tdn service encoding: literal
Using tdn schema namespace: http://www.onvif.org/ver10/network/wsdl
Saving samples/onvif/RemoteDiscoveryBinding.nsmap namespace mapping table
Using tds service name: DeviceBinding
Using tds service style: document
Using tds service encoding: literal
Using tds schema namespace: http://www.onvif.org/ver10/device/wsdl
Saving samples/onvif/DeviceBinding.nsmap namespace mapping table
Using tptz service name: PTZBinding
Using tptz service style: document
Using tptz service encoding: literal
Using tptz schema namespace: http://www.onvif.org/ver20/ptz/wsdl
Saving samples/onvif/PTZBinding.nsmap namespace mapping table
Using trt service name: MediaBinding
Using trt service style: document
Using trt service encoding: literal
Using trt schema namespace: http://www.onvif.org/ver10/media/wsdl
Saving samples/onvif/MediaBinding.nsmap namespace mapping table
Saving samples/onvif/soapClient.c client call stub functions
Saving samples/onvif/soapC.c serialization functions
Compilation successful (2 warnings)