//WEB_SERVICE #import "msxml3.dll" using namespace MSXML2; #import "C:/Program Files/Common Files/MSSoap/Binaries/MSSOAP1.dll" exclude("IStream", "ISequentialStream", "_LARGE_INTEGER","_ULARGE_INTEGER", "tagSTATSTG", "_FILETIME") using namespace MSSOAPLib; //END CString BeginSoap(CString UserName,CString Password,CString WebUrl); ISoapConnectorPtr SoapConnector; ISoapSerializerPtr Serializer; ISoapReaderPtr Reader; CString CXXXXXXXDlg::BeginSoap(CString UserName,CString Password,CString WebUrl) { HRESULT hr; CString theSoapBody; theSoapBody.Format(_T("<soap:Body><GetCSLoginTickets xmlns=/"http://tempuri.org//"><LogonName>%s</LogonName><Pwd>%s</Pwd></GetCSLoginTickets></soap:Body>"),UserName,Password); //创建SoapConnector类的对象 SoapConnector.CreateInstance(__uuidof(HttpConnector));
//指定Web
服务
的地址
SoapConnector->Property ["EndPointURL"] =(LPSTR)(LPCTSTR)WebUrl; //与Web服务连接 hr=SoapConnector->Connect(); if(FAILED(hr)) return NULL; //指定Web服务完成的操作 SoapConnector->Property ["SoapAction"] = _T("http://tempuri.org/GetCSLoginTickets"); //准备发送消息给Web服务 SoapConnector->BeginMessage(); // 创建SoapSerializer对象 Serializer.CreateInstance(__uuidof(SoapSerializer)); // 将serializer连接到connector的输入字符串 Serializer->Init(_variant_t((IUnknown*)SoapConnector->InputStream)); // 创建SOAP消息 Serializer->startEnvelope("soap","NONE",""); Serializer->SoapNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance"); Serializer->SoapNamespace("xsd","http://www.w3.org/2001/XMLSchema"); Serializer->writeXML((LPSTR)(LPCTSTR)theSoapBody); Serializer->endEnvelope(); //消息真正地发给Web服务 hr=SoapConnector->EndMessage(); if(FAILED(hr)) return NULL; // 读取响应 Reader.CreateInstance(__uuidof(SoapReader)); // 将reader联接到connector的输出字符串 Reader->Load(_variant_t((IUnknown*)SoapConnector->OutputStream), _T("")); return CString((const char *)Reader->RPCResult->text); }
VC6.0下访问WebService的组件
最新推荐文章于 2016-02-28 01:20:37 发布