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/