c++ gsoap怎么调用webservice
c++ gsoap调用webservice的方法步骤:
生成存客户端存根程序和框架
wsdl2h -o xxx.h xxx.wsdl(-t D:/gsoap-2.7/gsoap/typemap.dat)
soapcpp2 -L -x -i xxx.h(-I D:/gsoap-2.7/gsoap/import)
或直接自己编写xxx.h,并生成xxx.wsdl
//gsoap ns service name: xxx
//gsoap ns service style: rpc
//gsoap ns service encoding: literal
//gsoap ns service location: ht//localhost:8080
//gsoap ns schema namespace: ht/localhost:8080/xxx.wsdl
int ns__add(int a, int b, int* result);
客户端
1) 把如下生成的文件添加到项目:
stdsoap2.h,stdsoap2.cpp,
soapH.h,soapC.cpp,soapStub.h,
soapxxxProxy.h,soapxxxProxy.cpp,xxxSoap.nsmap
wsock32.lib2) 代理方式调用
#include "soapTestWebServiceProxy.h"
#include "Test www.hbbz08.com WebService.nsmap"
int main(int argc, char* argv[])
{
int result = 0;
TestWebServiceProxy proxy;
proxy.add(12, 23, &result);
} //w
服务端
1) 把如下生成的文件添加到项目:
stdsoap2.h,stdsoap2.cpp,
soapH.h,soapC.cpp,soapStub.h,
soapxxxService.h,soapxxxService.cpp,xxxSoap.nsmap
wsock32.lib
2) 实现接口函数
int TestWebServiceService::add(int a, int b, int *result)
{
*result = a+b;
return SOAP_OK;
} /
3) 开启服务
#include "soapTestWebServiceService.h"
#include "TestWebService.nsmap"
int main(int argc, char* argv[])
{
TestWebServiceService service;
service.run(8080);