Posted on 2009-10-19 15:51
S.l.e!ep.¢% 阅读(842)
评论(0) 编辑 收藏 引用 所属分类:
SOAP
//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); }
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/zhanghefu/archive/2008/06/23/2579529.aspx