WebService调用例子(vc6.0)
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
//以下SOA P环境配备(安装SoapToolkit30)
#import "msxml4.dll"
using namespace MSXML2;
#import "C:\Program Files\Common Files\MSSoap\Binaries\mssoap30.dll" \
exclude("IStream", "IErrorInf o", "ISequentialStream", "_LARGE_INTEGER", \
"_ULARGE_INTEGER", "tagSTA TSTG", "_FILETIME")
using namespace MSSOAPLib30;
//验证函数
BOOL ChkPwd(CString strID, CString strPWD, CString strIP)
{
BOOL bRet = FALSE;
try{
ISoapSerializerPtr Serializer;
ISoapReaderPtr Reader;
ISoapConnectorPtr Connector;
// Connect to the service.
Connector.CreateInstance(__uuidof(HttpConnector30));
//此处为你所需要调用的webservice.(/: 根据需要自己更改)
Connector->Property["EndPointURL"] = "/PassService/Service.asmx?wsdl";
Connector->Connect();
// 此处为服务端提供的验证接口.
Connector->Property["SoapAction"] = "http://10.0.0.10/V alidatePassport";
Connector->BeginMessage();
// Create the SoapSerializer object.
Serializer.CreateInstance(__uuidof(SoapSerializer30));
// Connect the serializer object to the input stream of the connector object.
Serializer->Init(_variant_t((IUnknown*)Connector->InputStream));
// Build the SOAP Message.
Serializer->StartEnvelope("","","");
Serializer->StartBody("");
Serializer->StartElement("V alidatePassport","http://10.0.0.10/","","");
//传送参数(ID)
Serializer->StartElement("loginName", "http://10.0.0.10/", "", "");
Serializer->WriteString((_bstr_t)(LPCTSTR)strID);
Serializer->EndEl ement();
Serializer->StartElement("password", "http://10.0.0.1/", "", "");
Serializer->WriteString((_bstr_t)(LPCTSTR)strPWD);
Serializer->EndEl ement();
Serializer->StartElement("userIP","http://10.0.0.10/","", "");
Serializer->WriteString((_bstr_t)(LPCTSTR)strIP);
Serializer->EndEl ement();
Serializer->EndEl ement();
Serializer->EndBody();
Serializer->EndEnvelope();
// Send the message to the XML Web service.
Connector->EndMessage();
// Read the response.
Reader.CreateInstance(__uuidof(SoapReader30));
// Connect the reader to the output stream of the connector object.
Reader->Load(_variant_t((IUnknown*)Connector->OutputStream), "");
//根据返回结果进行判断
if (pare(Reader->RpcResult->text) == 0)
{
bRet = TRUE;
}
}
catch(_com_error e)
{
}
return bRet;
}
void mian()
{
CoInitialize(NULL); //soap
BOOL bChk = ChkPwd(strID, strPWD, strIP);
CoUninitialize(); //soap
}