gSOAP Web Service 客户端应用实例
假设Web Service为Tester.asmx,接口名为getTime,参数为string类型,返回值为string类型,功能为在参数字符串后附加"(时间)"后返回,参数名为cData。
引用头:
#include <iostream>
#include "./WSDL/stdsoap2.h"
#include "./WSDL/soapTesterSoapProxy.h"
#include "./WSDL/TesterSoap.nsmap"
将soapcpp2生成的全部文件以及Tester.h文件,全部拷贝到当前项目根目录下的WSDL子目录下
请注意,仅拷贝.cpp与.h文件, 将所有文件添加到项目中,代码文件不使用预编译头
具体代码:
TesterSoapProxy oSvc;
_ns1__getTime oReq;
oReq.cData = (char *)malloc(20);
memset(oReq.cData, 0, 20);
memcpy(oReq.cData, "This is a test.", 15);
_ns1__getTimeResponse oRes;
int result = oSvc.getTime(&oReq, &oRes);
printf("Result=%s/r/nError Code=%d", oRes.getTimeResult, result);
free(oReq.cData);
请注意,错误代码定义在stdsoap2.h中