原理步骤
- 安装gsoap,本文选用版本为2.8.74
- 解析webservice接口,获得c++接口文件
1.wsdl2h -o outfile.h mymymy.wsdl
其中xxx,wsdl为下载好的接口文件,也可以直接换成wsdl的URL,例如:wsdl2h -o outfile.h http:xxxxxxxxxxxxx.wsdl
2.soapcpp2 -i outfile.h
此处可加一些参数,例如-i:生成c++封装;-x:不产生xml文件;-C仅生成客户端代码
测试代码
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "WebServiceImplServiceSoapBinding.nsmap"
#include "soapWebServiceImplServiceSoapBindingProxy.h"
using namespace std;
int main()
{
WebServiceImplServiceSoapBindingProxy proxy;
proxy.WebServiceImplServiceSoapBindingProxy_init(SOAP_C_UTFSTRING, SOAP_C_UTFSTRING);
ns1__receiveAlarmVAS *ns1__receiveAlarmVAS_=new ns1__receiveAlarmVAS();
ns1__receiveAlarmVAS_->alarmJson="{\"lineId\":2,\"stationId\":146,\"areaIds\":\"0\",\"alarmType\":43,\"alarmLevel\":\"0\",\"alarmInfo\":\"xxx\",\"alarmTime\":\"2018-01-02:47:05\"}";
ns1__receiveAlarmVASResponse *ns1__receiveAlarmVASResponse_=new ns1__receiveAlarmVASResponse;
int ret = proxy.receiveAlarmVAS(ns1__receiveAlarmVAS_, *ns1__receiveAlarmVASResponse_);
cout<<"12"<<endl;
printf("ret=%d,ns1__receiveAlarmVASResponse_->ns1__resultMessage=%d\n",ret,ns1__receiveAlarmVASResponse_->return_->message);
cout<<"ok"<<endl;
}