VB6.0通过SoapToolkit访问WebService问题

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:

文章中引用了网上的文章,如果作者有异议我将马上去掉。