AXIS应用2-编写C客户端
本文使用gSoap-win32来编写C客户端
1 下载gsoap-win32-2.7.zip
网址:主页http://gsoap2.sourceforge.net/
sourceforge.net下载http://sourceforge.net/project/showfiles.php?group_id=52781
2 安装gsoap-win32-2.7
用%GSOAP_HOME%代表gsoap-win32-2.7.zip解压后所在目录
2.1 建立环境变量
在桌面上右击[我的电脑]选择[属性],然后选择[高级]面板,在[高级]面板中点击[环境变量]
在弹出的面板中,在系统变量里建立GSOAP_HOME变量,值为gsoap-win32-2.7.zip解压后所在目录,在系统变量中找到Path变量并编辑,在其值最后面加上”; %GSOAP_HOME%/”
3 建立工程目录
helloClient
-HelloSVC.wsdl
4 由HelloSVC.wsdl生成C头文件
在命令行,进入helloClient工程所在目录并运行以下命令
>wsdl2h –c HelloSVC.wsdl |
5 由HelloSVC.h生成客户端文件
在命令行,进入helloClient工程所在目录并运行以下命令
>soapcpp2 –c -C HelloSVC.h |
6 建立VC++工程
在VC++ 6.0中新建一win32 console Application 工程名为helloClient(与3中的工程同一目录)
6.1 从%GSOAP_HOME%目录拷贝stdsoap2.h, stdsoap2.cpp文件到工程所在目录
6.2 在FileView中右击helloClient在弹出菜单中选择[添加文件到工程],添加的文件如下图
6.3在FileView中右击helloClient在弹出菜单中选择[设置], 如下图,分别设置soapC.c, soapClient.c, and stdsoap2.cpp选择[不使用预补偿页眉]
6.4在FileView中右击helloClient在弹出菜单中选择[设置], 如下图
为工程添加对wsock32.lib的连接
6.5 编写客户端代码(helloClient.cpp)
helloClient.cpp内容如下
#include "soapH.h" /* include generated proxy and SOAP support */
int main(int argc, char* argv[]) { ns1__sayHello sayHello; struct soap soap; if (argc > 1) sayHello._name = argv[1]; else { fprintf(stderr, "Usage: <name>/n"); return -1; } char *returnStr="wait"; soap_init(&soap); if (soap_call_ns1__sayHello(&soap, NULL, NULL, sayHello._name, &returnStr) == 0) printf("/nSayHello - %s /n", returnStr); else soap_print_fault(&soap, stderr); return 0; }
/* The namespace mapping table is required and associates namespace prefixes with namespace names: */ struct Namespace namespaces[] = { {"SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/"}, /* MUST be first */ {"SOAP-ENC", "http://schemas.xmlsoap.org/soap/encoding/"}, /* MUST be second */ {"xsi", "http://www.w3.org/1999/XMLSchema-instance"}, /* MUST be third */ {"xsd", "http://www.w3.org/1999/XMLSchema"}, {"ns1", "http://ws.jceun.org"}, /* Method namespace URI */ {NULL, NULL} }; |
6.6 组建工程
6.7 运行
在命令行,进入helloClient工程所在目录并运行以下命令
>cd Debug >helloClient ceun SayHello - Hello ceun!Tue Oct 09 14:40:53 CST 2007 |
参考文章
Use gSOAP to consume J2EE Web services created by WSAD through HTTP and HTTPS
http://www-128.ibm.com/developerworks/webservices/library/ws-soa-gsoap/