VC++6.0 调用webservice (使用MS SOAP)

近期VC6.0的老项目中需要增加一个调用远程webservice的功能,尝试了gSoap,很累很累得一番折腾之后,调用是成功了,但是因为gSoap返回的数据是封装好的,但gSoap资料匮乏,很难查到怎样从这些封装里面取出数据的方法,眼睁睁看着数据返回了,却无法处理。

折腾了好久,改用了微软自己的MSSOAP,很快搞定了,方法记录如下:

1. 安装soapsdk

下载:http://download.microsoft.com/download/2/e/0/2e068a11-9ef7-45f5-820f-89573d7c4939/soapsdk.exe)

备用下载:https://download.csdn.net/download/zhouyingge1104/12520216

 

2. 下载 MSSOAP30.dll和msxml4.dll,

备用下载:https://download.csdn.net/download/zhouyingge1104/12520216

下载之后,把这两个dll放到项目的debug目录中,也就是和exe一个目录。

3. 下载webService.h文件

备用下载:

4. 写程序:

#include "webService.h"

int main(int argc, char* argv[])
{
	printf("Hello World!\n");

	char* arc1[] = {"strXML"}; //参数名称
	char* arc2[] = {"<webService><head>XXX</head><request>XXX</request></webService>"}; //参数值

	CoInitialize(NULL); //设置单线程运行

	int code = webService("http://11.111.111.11:9010/InterfaceTest/sDataInfrace.asmx?wsdl", 
		"http://tempuri.org/", 
		"GetSampInfo", 
		1, 
		arc1, 
		arc2);

	CoUninitialize();
	
	printf("code:%d \n", code);

	return 0;
}

输出:

返回的是原始的字符串,这样就能在程序中直接读取并处理了。

#include "stdafx.h" #import "msxml4.dll" using namespace MSXML2; #import "C:/Program Files/Common Files/MSSoap/Binaries/mssoap30.dll" \ exclude("IStream", "IErrorInfo", "ISequentialStream", \ "_LARGE_INTEGER", "_ULARGE_INTEGER", "tagSTATSTG", "_FILETIME") using namespace MSSOAPLib30; //你机器得安装SOAP Toolkit3.0 ,1.0时,用using namespace时报错 void query(char *EndPointURL,char *NameSpace,char *method,int argv_len,char* args[],char* argv[]) { ISoapSerializerPtr Serializer; ISoapReaderPtr Reader; ISoapConnectorPtr Connector; // Connect to the service Connector.CreateInstance(__uuidof(HttpConnector30)); Connector->Property["EndPointURL"] = EndPointURL;//"http://localhost/WebService1/Service1.asmx"; Connector->Connect();//和服务器连接 // Begin message Connector->Property["SoapAction"] = _bstr_t(NameSpace) + _bstr_t(method);//"http://xin.org/getIP"; Connector->BeginMessage(); Serializer.CreateInstance(__uuidof(SoapSerializer30)); // 将serializer连接到connector的输入字符串 Serializer->Init(_variant_t((IUnknown*)Connector->InputStream)); // 创建SOAP消息 Serializer->StartEnvelope("","",""); Serializer->StartBody(""); Serializer->StartElement(method,NameSpace,"","");//命名空间必须有 for(int i=0;i<argv_len;i++) { Serializer->StartElement(args[i],NameSpace,"",""); Serializer->WriteString(argv[i]); Serializer->EndElement(); } Serializer->EndElement(); Serializer->EndBody(); Serializer->EndEnvelope(); // Send the message to the web service Connector->EndMessage(); // 读取响应 Reader.CreateInstance(__uuidof(SoapReader30)); // 将reader联接到connector的输出字符串 Reader->Load(_variant_t((IUnknown*)Connector->OutputStream), ""); printf("Answer: %s\n",(const char*) Reader->RpcResult->text); } int main(int argc, char* argv[]) { CoInitialize(NULL); char *EndPointURL="http://approve.share-su
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小鹰信息技术服务部

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值