1、gsoap是什么?
The gSOAP toolkit is an open source C and C++ software development toolkit forSOAP/XML Web services and generic (non-SOAP)C/C++ XML data bindings. The toolkit analyzes WSDLs and XML schemas (separately or as a combined set) and maps the XML schema types and the SOAP messaging protocols to easy-to-use and efficient C and C++ code. It also supports exposing (legacy) C and C++ applications as SOAP/XML Web services by auto-generating XML serialization code and WSDL specifications. Or you can simply use it toautomatically convert XML to/from C and C++ data. The toolkit supports options to generate pure ANSI C or C++ with or without STL.
这是gsoap介绍的原文,简单来说,gsoap就是一个工具,这个工具能够做的事情就是自动从WSDL和XML文档生成C/C++代码,或者是逆向。这就是我所理解的gsoap。
记录下:
gSOAP编译工具提供了一个SOAP/XML 关于C/C++ 语言的实现,从而让C/C++语言开发web服务或客户端程序的工作变得轻松了很多。绝大多数的C++web服务工具包提供一组API函数类库来处理特定的SOAP数据结构,这样就使得用户必须改变程序结构来适应相关的类库。与之相反,gSOAP利用编译器技术提供了一组透明化的SOAP API,并将与开发无关的SOAP实现细节相关的内容对用户隐藏起来。
gSOAP的编译器能够自动的将用户定义的本地化的C或C++数据类型转变为符合XML语法的数据结构,反之亦然。这样,只用一组简单的API就将用户从SOAP细节实现工作中解脱了出来,可以专注与应用程序逻辑的实现工作了。gSOAP编译器可以集成C/C++和Fortran代码(通过一个Fortran到C的接口),嵌入式系统,其他SOAP程序提供的实时软件的资源和信息;可以跨越多个操作系统,语言环境以及在防火墙后的不同组织。
gSOAP使编写web服务的工作最小化了。gSOAP编译器生成SOAP的代码来序列化或反序列化C/C++的数据结构。gSOAP包含一个WSDL生成器,用它来为你的web服务生成web服务的解释。gSOAP的解释器及导入器可以使用户不需要分析web服务的细节就可以实现一个客户端或服务端程序。
2、gsoap使用
gsoap通常带有两个工具: wsdl2h 和 soapcpp2。 wsdl2h主要是用来生成头文件的,而soapcpp2主要是利用wsdl2h生成的头文件来生成C文件或C++文件。
a、wsdl2h的使用
命令: wsdl2h 【-】 -o 头文件名 wsdl文件名或者url
例 : wsdl2h -o quote.h http://services.xmethods.net/soap/urn:xmethods-delayed-quotes.wsdl
Usage: wsdl2h [-a] [-c] [-d] [-e] [-f] [-g] [-h] [-I path] [-j] [-l] [-m] [-n name] [-N name] [-p] [-q name] [-r proxyhost:port] [-s] [-t typemapfile.dat] [-u]
[-v] [-w] [-x] [-y] [-z] [-o outfile.h] infile.wsdl infile.xsd http://www... ...
wsdl2h常用选项
-o 文件名,指定输出头文件
-n 名空间前缀 代替默认的ns
-c 产生纯C代码,否则是C++代码
-s 不要使用STL代码
-t 文件名,指定type map文件,默认为typemap.dat
-e 禁止为enum成员加上名空间前缀
type map文件用于指定SOAP/XML中的类型与C/C++之间的转换规则,比如在wsmap.dat里写。
关于typemap.dat,在下载的gsoap中是有另外一个,叫:WS-typemap.dat。 如果有多个wsdl文档,建议使用这个。
wsdl2h针对多个文档: wsdl2h.exe -sc -t WS-typemap.dat -o quote.h a.wsdl b.wsdl c.wsdl
b、soapcpp2的使用
命令: soapcpp2 【】 头文件名 【-I】 import路径
例 : soapcpp2 -L -c quote.h -I E:\gsoap-2.8\gsoap\import
soapcpp2常用选项
-C 仅生成客户端代码
-S 仅生成服务端代码
-c 产生纯C代码,否则是C++代码
-L 不要产生soapClientLib.c和soapServerLib.c文件
-I 指定import路径
-x 不要产生XML示例文件
-i 生成C++包装,客户端为xxxxProxy.h(.cpp),服务器端为xxxxService.h(.cpp)。
soapcpp2针对多个文档: soapcpp2 -L -c quote.h -I E:\gsoap-2.8\gsoap\import
其实多个wsdl合并只需要在生成头文件的时候注意就可以了,源文件是通过头文件得到的。
附: 工具命令
wsdl2h
Usage: wsdl2h [-a] [-c] [-d] [-e] [-f] [-g] [-h] [-I path] [-j] [-l] [-m] [-n name] [-N name] [-p] [-q name] [-r proxyhost:port] [-s] [-t typemapfile.dat] [-u]
[-v] [-w] [-x] [-y] [-z] [-o outfile.h] infile.wsdl infile.xsd http://www... ...
-a generate indexed struct names for local elements with anonymous types
-c generate C source code
-d use DOM to populate xs:any and xsd:anyType elements
-e don't qualify enum names
-f generate flat C++ class hierarchy
-g generate global top-level element declarations
-h display help info
-Ipath use path to find files
-j don't generate SOAP_ENV__Header and SOAP_ENV__Detail definitions
-l include license information in output
-m use xsd.h module to import primitive types
-nname use name as the base namespace prefix instead of 'ns'
-Nname use name as the base namespace prefix for service namespaces
-ofile output to file
-p create polymorphic types with C++ inheritance with base xsd__anyType
-qname use name for the C++ namespace for all service declarations
-rhost:port /* ??? 暂没理解 */
connect via proxy host and port
-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 don't generate unions
-v verbose output
-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
-z generate pointer-based arrays for backward compatibility < gSOAP 2.7.6e
infile.wsdl list of input sources (if none: use stdin)
soapcpp2
Usage: soapcpp2 [-1|-2] [-C|-S] [-L] [-a] [-c] [-d path] [-e] [-h] [-i] [-I path;path;...] [-l] [-m] [-n] [-p name] [-s] [-t] [-v] [-w] [-x] [infile]
-1 generate SOAP 1.1 bindings
-2 generate SOAP 1.2 bindings
-C generate client-side code only
-S generate server-side code only
-L don't generate soapClientLib/soapServerLib
-a use value of SOAPAction HTTP header to dispatch method at server side
-c generate C source code
-dpath use path to save files
-e generate SOAP RPC encoding style bindings
-h display help info
-i generate service proxies and objects inherited from soap struct
-Ipath use path(s) for #import
-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 save files with new prefix name instead of 'soap'
-s generate deserialization code with strict XML validation checks
-t generate code for fully xsi:type typed SOAP/XML messaging
-v display version info
-w don't generate WSDL and schema files
-x don't generate sample XML message files
infile header file to parse (or stdin)
参考:
http://blog.sina.com.cn/s/blog_4900f3fb0100j94p.html
http://gsoap2.sourceforge.net/
http://blog.csdn.net/Ocean2006/article/details/5490928