20080304 gsoap uclibc 1

使用gSoap开发Web Service C/C++客户端
Aigui.LIU@ihep.ac.cn
2006-08-02

一、开发环境准备
1、从gSoap官方网站 http://gsoap2.sourceforge.net下载软件
2、根据文档安装配置gSoap(略)

二、如何开发WEB服务客户端
1、基本流程
(1)从WEB服务提供者获取WEB Service的WSDL文件;
(2)使用gSoap工具wsdl2h,根据WSDL文件生成C/C++语法结构的头文件;
(3)使用gSoap预编译器soapcpp2,根据.h头文件中定义的信息来生成客户端代码框架;
(4)实现客户端例程;
(5)GCC编译客户端,生成可执行代码。

2、一个例子
(1)WEB服务Hello.jws(http://castor.ihep.ac.cn:8080/axis/Hello.jws):
public class Hello &leftsign;
public String hello(String name) &leftsign;
if(name==null)
name = "";
return name +", welcome to the world of web service!";
&rightsign;
&rightsign;
(2)获取WEB服务描述文件hello.wdsl
http://castor.ihep.ac.cn:8080/axis/Hello.jws?wsdl
(3)使用gSoap工具wsdl2h,根据WSDL文件生成C/C++语法结构的头文件hello.h
wsdl2h -c hello.wsdl
-c 表示生成纯C头文件,不加-c生成C++头文件
(4)使用gSoap预编译器soapcpp2,根据.h头文件中定义的信息来生成客户端代码框架
soapcpp2 -c hello.h
-c 表示生成纯C头代码,不加-c生成C++代码
(5)实现客户端例程hello.c
#include "soapH.h"
#include "HelloSoapBinding.nsmap"
int main()
&leftsign;
struct soap soap;
struct ns1__helloResponse ret;
soap_init(&soap);
if (soap_call_ns1__hello(&soap, NULL, NULL, "Aigui.LIU", &ret) == SOAP_OK)
printf("%s\\n", ret._helloReturn);
else
soap_print_fault(&soap, stderr);
soap_destroy(&soap);
soap_end(&soap);
soap_done(&soap);
return 0;
&rightsign;
(6)GCC编译客户端,生成可执行代码hello
$(CC) $(CFLAGS) -o hello hello.c soapC.c soapClient.c $(SOAPC)
其中(Makefile中定义),
GSOAP_PATH=/home/liuag/software/gsoap/gsoap-linux-2.6
SOAPC=$&leftsign;GSOAP_PATH&rightsign;/stdsoap2.c
CC=gcc
COFLAGS=-O2
CWFLAGS=-Wall
CIFLAGS=-I $&leftsign;GSOAP_PATH&rightsign;
CMFLAGS=
CFLAGS= $(CWFLAGS) $(COFLAGS) $(CIFLAGS) $(CMFLAGS)
(7)运行结果
$ ./hello
$ Aigui.LIU, welcome to the world of web service!

三、参考文献
1、http://gsoap2.sourceforge.net
2、gSoap User Guide

在实作SOAP讯息解析/建构的功能时,本文是重
用gSOAP程式库辅助软体介面的建构,gSOAP程
式库除可完成SOAP讯息的解析与建构之外,也
可产生客户端stub与伺服器端skeleton,如此可减
少程式设计师的负担.

本文利用gSOAP所
提供的程式库实作SOAP parser与message generator,而SOAP介面中的HTTP
Interface,虽然可自行设计,但本文则是重用thttp作为HTTP Interface,因为thttp
除具有执行效率良好的优点,并且拥有良好的安全机制,可以保护关键功能不被
窃取或攻击.

采用gSOAP辅助客户端程式的开发,使用的方法如下:
1. 使用wsdl2h从服务描述档产生对应的C语言标头档.
2. 以soapcpp2由C语言标头档产生客户端的stub.
3. 使用stub建构客户端程式.
第一步骤所产生的C语言标头档,是使用gSOAP工具时所产生的暂存档案,在
之后建构客户端的过程中并不会用到,而客户端的stub会负责将呼叫包装成
SOAP讯息经由网路传送到客户端,并且处理有关错误的讯息以及资料的序列
化,除此之外,stub也会将远端的功能包装成一系列可程式化介面,供程式设计
师使用,因此当程式设计师需使用关键的功能时,只需呼叫由gSOAP产生的
stub,即可使用关键运算功能.
软体工程师在开发客户端程式时,可能会发生错误,这时可用由Axis所提
供的TCPMonitor,来监控客户端雨嵌入式系统之间传送的讯息.

No hablo bien espagnol
pero credo que es bastante para un contenudo technico !?

Ho encrontrado esta error
la solucion fue d\’incluir el "nsmap" file in el "main"

Aqui las lineas que ho incluido en el "soapClient.cpp"

//// Ajout de JLV
#include "AjoutServiceSoap.nsmap"
#include "soapAjoutServiceSoapProxy.h"

const char server[] = "http://localhost/AjoutWS/AjoutService.asmx";

int main(int argc, char **argv)
&leftsign;
AjoutServiceSoap s;
struct soap soap;
soap_init(&soap);
_ns1__Ajout req;
req.soap = &soap;
int x=1, y=2;
req.x=x; req.y=y;

struct soap soap2;
soap_init(&soap2);
_ns1__AjoutResponse rep;
rep.soap = &soap2;

s.__ns1__Ajout(&req, &rep);
printf("reponse=%d", rep.AjoutResult);
soap_destroy(&soap2);
soap_end(&soap2);
soap_destroy(&soap);
soap_end(&soap);
return 0;
&rightsign;
//// Ajout de JLV

there is also a Qt based application server that supports XML-RPC based on web services: FEAST.

http://trolltech.com/partners/direct…ers/clausmark/

http://dist.trolltech.com/pdf/Clausm…nBrief_web.pdf

http://www.clausmark.com/feast_en.phtml

FEAST handles the concurrent user situation as well as taking care of
backend data sources with connection pooling etc. Actually FEAST is more
then a server; it is development framework for distributed applications
based on Qt.

FEAST uses SOAP HTTP as the communication protocol (it does not rely on
gSOAP though and does away with several of the limitations of gSOAP) so it is easy to use over the internet through firewalls

This is a post more for gSOAP than Qt.

It\’s about the "error LNK2001: unresolved external symbol _namespaces" reported by xgoan.

Since this is one of the few places i\’ve found mentioning this problem, i just want to post the solution for anyone suffering the same problem.

The fix is to #include the nsmap file that is generated by gSOAP in your own cpp files:

#include "soapH.h" // or whatever it is called, you must already have it
#include "whatever.nsmap" // this is what you have to add to fix the problem

The solution was originally posted in an spanish forum:
http://www.programacion.com/foros/37/msg/171805

基于.net开发平台项目案例集锦

he author has port gSoap to vXworks. In fact, it is written in ANSI C
and easy to port other platforms. I have ported it to ARM7TDMI +
uCLinux

for more infomation, please refer to author\’s website:

http://www.cs.fsu.edu/~engelen/soap.html

http://www.info-life.cn/?cat=3

历史博文

标签:, , , ,
十一月 30, 2008 at 11:51 上午 by yippee 1,059 次
Category: Info
Tags: , , , ,