欢迎来到天天文库
浏览记录
ID:6033949
大小:67.00 KB
页数:8页
时间:2017-12-31
《vc6控制台程序利用soaptoolkit3.0调用webservice》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、vc6控制台程序利用SoapToolkit3.0调用WebServicevc6控制台程序利用SoapToolkit3.0调用WebService1. 首先要安装SoapToolkit3.0安装包并安装(我的安装目录为:D:ProgramFilesMSSOAP)2.新建vc控制台程序(空项目),项目名称:WinConsole6InvokeWebService,添加一个c++源文件(main.cpp),将SOAP安装目录下的lib文件D:ProgramFilesMSSOAPLibmssoap30.lib复制到项目文件夹下。3。添加源代码:?12345678
2、910111213141516#include#include#include #import"msxml4.dll" usingnamespacestd;usingnamespaceMSXML2; #import"C:ProgramFilesCommonFilesMSSoapBinariesMSSOAP30.dll" exclude("IStream","IErrorInfo","ISequentialStream","_LARGE_INTEGER", "_ULA
3、RGE_INTEGER","tagSTATSTG","_FILETIME") usingnamespaceMSSOAPLib30; voidquery(char*EndPointURL,char*Namespace,char*method,vector&v){ ISoapSerializerPtrSerializer; ISoapReaderPtrReader; ISoapConnectorPtrConnector; 1718192021222324252627282930313233 //Connecttoth
4、eservice Connector.CreateInstance(__uuidof(HttpConnector30)); Connector->Property["EndPointURL"]=EndPointURL; //接口位置 Connector->Connect(); //和服务器连接 //Beginmessage Connector->Property["SoapAction"]=_bstr_t(Namespace)+_bstr_t(m
5、ethod); Connector->BeginMessage(); Serializer.CreateInstance(__uuidof(SoapSerializer30)); //将serializer连接到connector的输入字符串 Serializer->Init(_variant_t((IUnknown*)Connector->InputStream)); //创建SOAP消息 Serializer->StartEnvelope("soap","",""); Serializer->StartBod
6、y("body"); Serializer->StartElement(method,Namespace,"","");//命名空间必须有 for(vector::iteratorit=v.begin();it!=v.end();it++) { Serializer->StartElement("username",Namespace,"",""); Serializer->WriteString(it->c_str()); Serializer->EndElement(); }
7、 Serializer->EndElement();34353637383940414243444546474849 Serializer->EndBody(); Serializer->EndEnvelope(); Connector->EndMessage(); //Sendthemessagetothewebservice //读取响应 Reader.CreateInstance(__uuidof(SoapReader30)); Reader->Load(_variant_t((
此文档下载收益归作者所有