分享

vc中如何调用webservice? VC/MFC / 进程/线程/DLL...

 素行 2007-05-10
用msxml+soap  
  #import   "msxml4.dll"    
  using   namespace   MSXML2;  
  #import   "C:\Program   Files\Common   Files\MSSoap\Binaries\mssoap30.dll"   \  
                          exclude("IStream",   "IErrorInfo",   "ISequentialStream",   "_LARGE_INTEGER",   \  
                                          "_ULARGE_INTEGER",   "tagSTATSTG",   "_FILETIME")  
  using   namespace   MSSOAPLib30;  
   
   
  string   GetCompanyNameFromWeb(void)  
  {  
  try  
  {  
  ISoapSerializerPtr   Serializer;  
  ISoapReaderPtr   Reader;  
  ISoapConnectorPtr   Connector;  
  //   Connect   to   the   service.  
  Connector.CreateInstance(__uuidof(HttpConnector30));  
  //Connector->Property["EndPointURL"]   =   "http://www./UpLoadImage.asmx";  
  Connector->Property["EndPointURL"]   =   "http://localhost/WebOfficeValidateService/Validate.asmx";  
  Connector->Connect();  
   
  //   Begin   the   message.  
  Connector->Property["SoapAction"]   =   "http:///GetCompanyName";  
  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("GetCompanyName","http:///","","");  
  Serializer->StartElement("SerialNum","http:///","","");  
  Serializer->WriteString(m_strSerial.c_str());  
  Serializer->EndElement();  
  Serializer->EndElement();  
  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.  
  VARIANT_BOOL   bl   =   Reader->Load(_variant_t((IUnknown*)Connector->OutputStream),   "");  
   
   
  //   Display   the   result.  
  _bstr_t   bstrResult   =   Reader->RpcResult->text;  
  return   (char*)bstrResult;  
  }  
  catch(_com_error   &e)  
  {  
  return   NULL;  
  }  
  }  

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多