背景需求。
1、有一个webservice的server端。具体表现为一个link——http:\XXXXXXXXXXXXXXXXXXX.com?wsdl
2、下载一个最gsoap包,(自行前往官网下载)。解压目录为 D:\workspace\2、LIS\gsoap-2.8。
操作流程。
1、在 bin\win32 目录下建一个空的头文件WebService.h(好像可以不用做);
2、再建立一个字符转换规则文件wsmap.dat,文件内容为xsd__string = | std::wstring | wchar_t*(为了某种程度上支持中文);
3、启动cmd,进入到 \bin\win32 目录,调用wsdl2h.exe生成头文件接口定义,命令为:(生成.h文件)
wsdl2h -o WebService.h -n WS -t wsmap.dat http://XXXXXXXXXXXXXXXXXXXXXX.asmx?WSDL
此步完成后,WebService.h文件里面就有内容了。
wsdl2h 的操作命令如下:
- -o 文件名,指定输出头文件
- -n 名空间前缀 代替默认的ns
- -c 产生纯C代码,否则是C++代码
- -s 不要使用STL代码
- -t文件名,指定type map文件,默认为typemap.dat
- -e 禁止为enum成员加上名空间前缀
4、在命令行输入soapcpp2 -j WebService.h(解析WebService.h,生成存根程序);
然后生成的文件中包含server和client。做client千万不要把server加入其中。
整个项目的源文件列表如下:
main.cpp(玩家手动生成)
soapC.cpp(本步骤生成)
soapH.h(本步骤生成)
soapLimsInfoServiceImplServiceSoapBindingProxy.cpp(本步骤生成)
soapLimsInfoServiceImplServiceSoapBindingProxy.h(本步骤生成)
soapStub.h(本步骤生成)
stdsoap2.cpp(gsoap文件夹下有)
stdsoap2.h(gsoap文件夹下有)
5、新建项目。额外的文件列表入步骤4.
在工程的头文件中加入#include “WeatherWSSoap.nsmap”,否则会有命名空间编译出错的问题.
6、我的main代码
1 #include "soapLimsInfoServiceImplServiceSoapBindingProxy.h"
2
3 #include "LimsInfoServiceImplServiceSoapBinding.nsmap"
4
5 using namespace std;
6
7 int main()
8 {
9 LimsInfoServiceImplServiceSoapBindingProxy webservice;
10
11 WS1__getPatientInformation barcode = WS1__getPatientInformation();
12
13 WS1__getPatientInformationResponse pantientRes = WS1__getPatientInformationResponse();
14
15 string tmp = "157961253";
16 barcode.WS1__barcode = &tmp;
17
18 int result = webservice.getPatientInformation(&barcode, pantientRes);
19
20 if (SOAP_OK == result)
21 {
22 cout << *pantientRes.out;
23 }
24
25 cin.get();
26 return 0;
27 }
原文链接: https://www.cnblogs.com/yangtoujunshi/p/8418933.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/268871
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!