加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

webservice 使用vs2005生成代理

发布时间:2020-12-16 22:17:11 所属栏目:安全 来源:网络整理
导读:?使用类似代码 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

?使用类似代码 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","NONE",""); Serializer->WriteString((LPCTSTR)Globle_User); Serializer->EndElement(); Serializer->StartElement("pass",""); 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),"");??//加载返回数据

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读