gsoap-实现c++与java的webservice通信

原理步骤

  • 安装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();//sendMsg.h  196
	ns1__receiveAlarmVAS_->alarmJson="{\"lineId\":2,\"stationId\":146,\"areaIds\":\"0\",\"alarmType\":43,\"alarmLevel\":\"0\",\"alarmInfo\":\"xxx\",\"alarmTime\":\"2018-01-02:47:05\"}";//此处中文格式需为utf8,不然发送过去会有乱码,只需要修改alarmLevel,四个报警等级
	ns1__receiveAlarmVASResponse *ns1__receiveAlarmVASResponse_=new ns1__receiveAlarmVASResponse;
	//sendMsg.H 234
	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;	
}

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值