gsoap 2.8 学习调用webservice
1.使用gsoap工具 生成对应的头文件
wsdl2h.exe -c++ -s -nEReq -NEReq -o ERequest.h http://xxx.xxx.xxx.xxx:xxxx/RequestNote?wsdl (可接多个wsdl)
2.使用头文件生成对应的代理类
soapcpp2.exe -C -c++ -pEReq -x -I D:\gsoap-2.8\gsoap\import -i ERequest.h
注意使用多个wsdl生成是记得修改代理类中 默认的的namespace文件否则调用会出现SOAP_SVR_FAULT。
然后开始调用代理类来调用webservice
int _tmain(int argc, _TCHAR* argv[])
{
string endpoint = "http://168.168.252.60:8080/HIS4LISServiceTest/RISFeeInfo.asmx";
int iResult;
char XML[1024] = "参数";
RISFeeInfoSoapProxy Soap = RISFeeInfoSoapProxy(endpoint.c_str(),SOAP_XML_TREE|SOAP_C_UTFSTRING);
Soap.mode|=SOAP_C_UTFSTRING;
Soap.recv_timeout = 5;
Soap.send_timeout = 5;
Soap.connect_timeout = 5;
Soap.accept_timeout = 5;
_EReq1__InputFeeInfo *pInputFeeInfo = new _EReq1__InputFeeInfo();
_EReq1__InputFeeInfoResponse InputFeeInfoResponse;
pInputFeeInfo->message = XML;
iResult = Soap.InputFeeInfo(pInputFeeInfo,InputFeeInfoResponse);
if(SOAP_OK!=iResult)
{
//提示
//接口调用失败
string ErrorMessage = "回写耗材费用失败\r\n错误代码:"+(iResult);
cout<<ErrorMessage.c_str()<<endl;
}
else
{
cout<<InputFeeInfoResponse.InputFeeInfoResult<<endl;
}
}