当前位置 : 主页 > 网页制作 > Nodejs >

webservice 使用vs2005生成代理

来源:互联网 收集:自由互联 发布时间:2021-06-24
使用类似代码 CoInitialize(NULL); HRESULThr=S_OK; inthiResult; CComBSTRusername=Globle_User; CComBSTRpassword=Globle_Pass; CService*debug=newCService; //代理对象 //可以调用SetUrl动态设置Web服务地址 CStringurl; url=L"htt

 使用类似代码 CoInitialize(NULL); HRESULT hr = S_OK; int hiResult; CComBSTR username = Globle_User; CComBSTR password = Globle_Pass; CService* debug = new CService; // 代理对象 // 可以调用SetUrl动态设置Web服务地址 CString url; url = L"http://" + NetAddress + L"/service.asmx?op=login"; debug->SetUrl(url); hr = debug->login(username, password, &hiResult); //注意,返回值是以指针形式反回的 if(FAILED(hr)) { } delete debug; CoUninitialize(); 方法二:直接使用soap方法访问webservice ISoapSerializerPtr   Serializer; ISoapReaderPtr   Reader; ISoapConnectorPtr   Connector; IDataEncoderFactoryPtr encoderFc; HRESULT hr; CoInitialize(NULL); if(FAILED(Connector.CreateInstance(__uuidof(HttpConnector30))))    //创建对象 { AfxMessageBox(L"soap失败"); return -1; } CString url = L"http://" + NetAddress + L"/service.asmx?wsdl"; Connector->Property["EndPointURL"] = (LPCTSTR)url; Connector->Connect(); //   Begin  the   message.  //消息体 Connector->Property["SoapAction"]   = "http://tempuri.org/login"; //函数体参数 Connector->BeginMessage(); Serializer.CreateInstance(__uuidof(SoapSerializer30)); Serializer->Init(_variant_t((IUnknown*)Connector->InputStream)); //   Build  the   SOAP   Message. try{ Serializer->StartEnvelope("","",""); Serializer->StartBody(""); Serializer->StartElement("login","http://tempuri.org/","",""); Serializer->StartElement("ID","http://tempuri.org/","NONE",""); Serializer->WriteString((LPCTSTR)Globle_User); Serializer->EndElement(); Serializer->StartElement("pass","http://tempuri.org/","NONE",""); Serializer->WriteString((LPCTSTR)Globle_Pass); Serializer->EndElement(); Serializer->EndElement(); Serializer->EndBody(); hr = Serializer->EndEnvelope(); Connector->EndMessage(); Reader.CreateInstance(__uuidof(SoapReader30)); Reader->Load(_variant_t((IUnknown*)Connector->OutputStream),"");  //加载返回数据

网友评论