面对现实,超越自己
逆水行舟,不进则退
posts - 269,comments - 32,trackbacks - 0

1.介绍

 

    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服务的细节就可以实现一个客户端或服务端程序。下面是gSOAP的一些特点:

 

l        gSOAP编译器可以根据用户定义的C和C++数据结构自动生成符合SOAP的实例化代码。

l        gSOAP支持WSDL 1.1, SOAP 1.1, SOAP 1.2, SOAP RPC 编码方式以及 literal/document 方式.

l        gSOAP是少数完全支持SOAP1.1 RPC编码功能的工具包,包括多维数组及动态类型。比如,一个包含一个基类参数的远程方法可以接收客户端传来的子类实例。子类实例通过动态绑定技术来保持一致性。

l        gSOAP 支持 MIME (SwA) 和 DIME 附件包。

l        gSOAP是唯一支持DIME附件传输的工具包。它允许你在保证XML可用性的同时能够以最快的方式(流方式)传递近乎无大小限制的二进制数据。

l        gSOAP 支持 SOAP-over-UDP。

l        gSOAP 支持 IPv4 and IPv6.

l        gSOAP 支持 Zlib deflate and gzip compression (for HTTP, TCP/IP, and XML file storage)。

l        gSOAP 支持 SSL (HTTPS)。

l        gSOAP 支持 HTTP/1.0, HTTP/1.1 保持连接, 分块传输及基本验证。

l        gSOAP 支持 SOAP 单向消息。

l        gSOAP 包含一个 WSDL 生成器,便于web服务的发布。

l        gSOAP 包含一个WSDL解析器 (将WSDL转换为gSOAP头文件),可以自动化用户客户端及服务端的开发。

l        生成可以单独运行的web服务及客户端程序。

l        因为只需要很少内存空间,所以可以运行在类似Palm OS, Symbian, Pocket PC的小型设备中。

l        适用于以C或C++开发的web服务中。

l        跨平台:Windows, Unix, Linux, Mac OS X, Pocket PC, Palm OS, Symbian等。

l        支持序列化程序中的本地化C/C++数据结构。

l        可以使用输入和输出缓冲区来提高效率,但是不用完全消息缓冲来确定HTTP消息的长度。取而代之的是一个三相序列化方法。这样,像64位编码的图像就可以在小内存设备(如PDA)中以DIME附件或其他方式传输。

l        支持C++单继承,动态绑定,重载,指针结构(列表、树、图、循环图,定长数组,动态数组,枚举,64位2进制编码及16进制编码)。

l        不需要重写现有的C/C++应用。但是,不能用unions,指针和空指针来作为远程方法调用参数的数据结构中元素。

l        三相编组:1)分析指针,引用,循环数据结构;2)确定HTTP消息长度;3)将数据序列化位SOAP1.1编码方式或用户定义的数据编码方式。

l        双相编组:1)SOAP解释及编码;2)分解“forward”指针(例如:分解SOAP中的href属性)。

l        完整可定制的SOAP错误处理机制。

l        可定制的SOAP消息头处理机制,可以用来保持状态信息

gsoap通常带有两个工具: wsdl2h 和 soapcpp2。 wsdl2h主要是用来生成头文件的,而soapcpp2主要是利用wsdl2h生成的头文件来生成C文件或C++文件。 

以下是README.txt中示例:

Example translation of WSDL to code in two steps:
$ wsdl2h -s -o calc.h http://www.cs.fsu.edu/~engelen/calc.wsdl
$ soapcpp2 calc.h

Windows下命令行运行:

       wsdl2h.exe -o TestServices.h http://192.168.20.242/ClientUpdateWebService.asmx?WSDL
       soapcpp2 TestServices.h 


出现如下错误:Critical error: #import: Cannot open file "stlvector.h" for reading.你需要在gsoap\import下把这个文件拷贝过来。

 wsdl2h
**  The gSOAP WSDL/Schema processor for C and C++, wsdl2h release 2.8.5
**  Copyright (C) 2000-2011 Robert van Engelen, Genivia Inc.
**  All Rights Reserved. This product is provided "as is", without any warranty.

**  The wsdl2h tool is released under one of the following two licenses:
**  GPL or the commercial license by Genivia Inc. Use option -l for details.

Usage: wsdl2h [-a] [-c] [-d] [-e] [-f] [-g] [-h] [-I path] [-i] [-j] [-k] [-l] [
-m] [-n name] [-N name] [-p|-P] [-q name] [-r proxyhost[:port[:uid:pwd]]] [-s] [
-t typemapfile] [-u] [-v] [-w] [-W] [-x] [-y] [-z#] [-_] [-o outfile.h] infile.w
sdl 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, xs:anyType, and xs:anyAttribute
-e      don't qualify enum names
-f      generate flat C++ class hierarchy
-g      generate global top-level element declarations
-h      display help info
-i      don't import (advanced option)
-Ipath  use path to find files
-j      don't generate SOAP_ENV__Header and SOAP_ENV__Detail definitions
-k      don't generate SOAP_ENV__Header mustUnderstand qualifiers
-l      display license information
-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 from base xsd__anyType
-P      don't create polymorphic types with C++ inheritance from xsd__anyType
-qname  use name for the C++ namespace of all declarations
-rhost[:port[:uid:pwd]]
        connect via proxy host, port, and proxy credentials
-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)
-W      suppress warnings
-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.15: qualify element/attribute referenced members
-_      don't generate _USCORE (replace with UNICODE _x005f)
infile.wsdl infile.xsd http://www list of input sources (if none: use stdin) 
soapcpp2
Usage: soapcpp2 [-1|-2] [-C|-S] [-T] [-L] [-a] [-b] [-c] [-d path] [-e] [-f N] [
-h] [-i] [-I path;path;] [-k] [-l] [-m] [-n] [-p name] [-s] [-t] [-u] [-v] [-
w] [-x] [-y] [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
-T      generate server auto-test code
-L      don't generate soapClientLib/soapServerLib
-a      use SOAPAction HTTP/WSA header to invoke server-side operations
-b      serialize byte arrays char[N] as string
-c      generate C source code
-dpath  use path to save files
-e      generate SOAP RPC encoding style bindings
-fN     file split of N XML serializer implementations per file (N>=10)
-h      display help info
-Ipath  use path(s) for #import
-i      generate C++ service proxies and objects inherited from soap struct
-j      generate C++ service proxies and objects that share a soap struct
-k      generate data structure walkers (experimental)
-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'
-qname  use name as the C++ namespace of all declarations
-s      generate deserialization code with strict XML validation checks
-t      generate code for fully xsi:type typed SOAP/XML messaging
-u      uncomment comments in WSDL/schema output by suppressing XML comments
-v      display version info
-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
infile  header file to parse (or stdin)          
其他相关链接: http://www.cppblog.com/woaidongmao/archive/2008/05/28/51400.html
posted on 2012-11-16 17:14 王海光 阅读(2912) 评论(0)  编辑 收藏 引用 所属分类: 工具

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理