您的位置:首页 > 其它

webservice 开发 axis2 简单部署服务 gSoap 客户端通信

2013-02-18 20:08 615 查看
WebService 的服务端
webservice 开发 axis2 简单部署服务 就是用前一章中的服务端

wsdl如下:

http://localhost:8080/axis2/services/SimpleService?wsdl

下载 gsoap 2.8 版本

第一步生成头文件:

wsdl2h –o hello.h -s http://localhost:8080/axis2/services/SimpleService?wsdl
参数说明 -s 不要使用STL代码

第二步 根据头文件生成stub

soapcpp2.exe -i -C -x hello.h -IF:\gsoap-2.8\gsoap\import

参数说明 -i 直接使用C++包装类 -x 不要生成一堆看了就恶心的xml -C 只生成客户端相关代码 -I 指定import路径

第三步 VS2008 创建 命令行工程 ws5

第四步 编辑工程属性 C/C++ -> 预编译头 -> 创建/使用预编译头 选择 不使用预编译头

第五步 编辑工程属性 链接器->输入->附件依赖项 输入 WSock32.Lib

第六步 把刚才gsoap生成的文件 soapH.h soapC.c soapStub.h soapClient.c

和gsoap文件夹下的 stdsoap2.h stdsoap2.c 拷贝到当前工程下面

第七步 实现

C代码







#include "stdafx.h"

#include <locale.h>
#include <stdio.h>
#include <stdlib.h>

#include "soapH.h"
#include "SimpleServiceSoap11Binding.nsmap"

int _tmain(int argc, _TCHAR* argv[])

{
struct soap *soap = soap_new();
struct _ns1__getGreetingResponse out;

soap->mode|=SOAP_C_MBSTRING;
soap_set_mode(soap,SOAP_C_MBSTRING);
setlocale(0,"chs");

struct _ns1__getGreeting resq;
resq.name="超人";
if(soap_call___ns1__getGreeting(soap,NULL,NULL,&resq,&out)==SOAP_OK){

printf("%s\n",out.return_);
}

printf("Press enter to continue ...");
getchar();
return 0;
}

#include "stdafx.h"

#include <locale.h>
#include <stdio.h>
#include <stdlib.h>

#include "soapH.h"
#include "SimpleServiceSoap11Binding.nsmap"

int _tmain(int argc, _TCHAR* argv[])
{
struct soap *soap = soap_new();
struct _ns1__getGreetingResponse out;

soap->mode|=SOAP_C_MBSTRING;
soap_set_mode(soap,SOAP_C_MBSTRING);
setlocale(0,"chs");

struct _ns1__getGreeting resq;
resq.name="超人";
if(soap_call___ns1__getGreeting(soap,NULL,NULL,&resq,&out)==SOAP_OK){
printf("%s\n",out.return_);
}

printf("Press enter to continue ...");
getchar();
return 0;
}


输出结果:

你好 超人
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: