gsoap應用---利用gsoap工具生成代碼

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
發佈了35 篇原創文章 · 獲贊 5 · 訪問量 28萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章