VB6.0通過SoapToolkit訪問WebService問題

來源:互聯網
上載者:User

 

VB6.0通過SoapToolkit訪問WebService

 

    在VB6.0中怎麼去訪問一個WebService網上有很多的執行個體,大家很容易搜到,這裡就不細說了。架設和使用可以看看這篇文章《使用 Microsoft SOAP Toolkit 2.0 建立安全 Web 服務 》。

    但在使用時總會遇到很多的問題。先收錄兩種最常見的問題如下:

    1 使用MSSoap.SoapClient對象

    該對象對低版本的WSDL能夠支援,但遇到高版本的WSDL就會出現以下的錯誤:

      訪問WebService錯誤WSDLReader:Analyzing the WSDL file failed HRESULT=0x80004005 
      - WSDLReader:Initialization of service failed HRESULT=0x80004005 
      - WSDLService:Initialization of the port for service JaxRpcOutAccessService failed HRESULT=0x80004005 
      - WSDLPort:Analyzing the binding information for port VioOutAccess failed HRESULT=0x80004005 
      - WSDLPort:An operation for port VioOutAccess could not be initialized HRESULT=0x80004005 
      - WSDLOperation:Initializing of the input message failed for operation queryVioSurveil HRESULT=0x80004005 
      - WSDLOperation:Initialization of a SoapMapper for operation queryVioSurveil failed HRESULT=0x80004005 
      - SoapMapper:The SoapMapper for element string could not be created HRESULT=0x80004005 
      - SoapMapper:The schema definition with a targetnamespace of http://schemas.xmlsoap.org/soap/encoding/ for SoapMapper string could not be found HRESULT=0x80004005

      這個問題一般是因為WSDL版本太高soapclient對象支援不好造成的,解決辦法就是換用MSSOAPLib30.SoapClient30對象。

      2 使用MSSOAPLib30.SoapClient30對象

      該版本支援的WSDL版本較MSSOAPLib.SoapClient略高,但最新的版本也是不支援的。該版本常見的錯誤如下:

      訪問WebService錯誤SoapMapper:The schema definition with a targetnamespace of http://schemas.xmlsoap.org/soap/encoding/ for SoapMapper string could not be found HRESULT=0x80004005: 未指定的錯誤
       - SoapMapper:The SoapMapper for element string could not be created HRESULT=0x80004005: 未指定的錯誤
       - WSDLOperation:Initialization of a SoapMapper for operation queryVioSurveil failed HRESULT=0x80004005: 未指定的錯誤
       - WSDLOperation:Initializing of the input message failed for operation queryVioSurveil HRESULT=0x80004005: 未指定的錯誤
       - WSDLPort:An operation for port VioOutAccess could not be initialized HRESULT=0x80004005: 未指定的錯誤
       - WSDLPort:Analyzing the binding information for port VioOutAccess failed HRESULT=0x80004005: 未指定的錯誤
       - WSDLService:Initialization of the port for service JaxRpcOutAccessService failed HRESULT=0x80004005: 未指定的錯誤
       - WSDLReader:Analyzing the WSDL file failed HRESULT=0x80004005: 未指定的錯誤
       - Client:One of the parameters supplied is invalid. HRESULT=0x80070057: 參數不正確。

      2.1 這個問題是因為,WSDL少type(WSDL描述可以看看這裡),就是

      <types>
 <schema targetNamespace="http://tempuri.org/xsd"
  xmlns="http://www.w3.org/2001/XMLSchema"
  xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
  elementFormDefault="qualified" >
 </schema>
</types> 

      如果WebService是自己發布的話則可以修改相應的部分使WSDL能夠被MSSOAPLib30.SoapClient30對象所支援,否則就只能在VB6.0和高版本的WSDL之間建立一個橋樑。比如用.net訪問WSDL,然後VB6.0再去調用.NET。

      2.2 上一個問題還有一個可能性就是WSDL命名空間(暫且這麼叫)的問題。

      例如:

      <wsdl:definitions xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
                  xmlns:apachesoap="http://xml.apache.org/xml-soap"
                  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                  xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
                  xmlns:intf="http://XXX/xxx/xxx/xxx"
                  xmlns:impl="http://xxx/xxx/xxx/xxx"
                  targetNamespace="http://xxx/xxx/xxx/xxx"
                  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">

      比較關鍵的兩個地方是xmlns:xsd="http://www.w3.org/2001/XMLSchema"和xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"對應著

      <wsdl:message name="xxx">
          <wsdl:part name="wsxlh" type="soapenc:string" />
          <wsdl:part name="xmlDoc" type="soapenc:string" />
      </wsdl:message>

      裡面的type="soapenc:string"。現在這樣的配置一般VB6.0不能正確的解析,如果要能正確額解析就要把xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 改為xmlns:soapenc="http://www.w3.org/2001/XMLSchema" ;或是把type="soapenc:string"改為type="xsd:string"。這樣VB6.0就能正確的訪問了。

      這方面的問題網上都只有提問,而沒有回答的。這篇文章也是自己實踐得來的結果,如有不正確的地方還望大家能夠不吝賜教。

      PS:

      文章中引用了網上的文章,如果作者有異議我將馬上去掉。

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.