使用ASP.NET使用PHP SOAP web服务

时间:2023-01-15 16:56:19

I'm having some major issues trying to consume my PHP SOAP webservice using ASP.NET. The webservice in question is based on the PHP SOAP extension and is descibed by the following WSDL:

在使用ASP.NET使用PHP SOAP web服务时,我遇到了一些主要问题。所涉及的web服务基于PHP SOAP扩展,并由以下WSDL进行描述:

<?xml version="1.0" encoding="UTF-8" ?>
<definitions name="MyServices"
  targetNamespace="http://mydomain.com/api/soap/v11/services"
  xmlns:tns="http://mydomain.com/api/soap/v11/services"
  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:xsd1="http://mydomain.com/api/soap/v11/services"
  xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
  xmlns="http://schemas.xmlsoap.org/wsdl/">

<types>
    <schema targetNamespace="http://mydomain.com/api/soap/v11/services" xmlns="http://www.w3.org/2001/XMLSchema">
        <complexType name="ServiceType">
            <all>
                <element name="id" type="xsd:int" minOccurs="1" maxOccurs="1" />
                <element name="name" type="xsd:string" minOccurs="1" maxOccurs="1" />
                <element name="cost" type="xsd:float" minOccurs="1" maxOccurs="1" />
            </all>
        </complexType>
        <complexType name="ArrayOfServiceType">
            <all>
                <element name="Services" type="ServiceType" minOccurs="0" maxOccurs="unbounded" />
            </all>
        </complexType>
    </schema>
</types>


<message name="getServicesRequest">
    <part name="postcode" type="xsd:string" />
</message>

<message name="getServicesResponse">
  <part name="Result" type="xsd1:ArrayOfServiceType"/>
</message>

<portType name="ServicesPortType">
  <operation name="getServices">
    <input message="tns:getServicesRequest"/>
    <output message="tns:getServicesResponse"/>
  </operation>
</portType>

<binding name="ServicesBinding" type="tns:ServicesPortType">
  <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
  <operation name="getServices">
    <soap:operation soapAction="http://mydomain.com/api/soap/v11/services/getServices" />
    <input>
      <soap:body use="encoded" namespace="urn:my:services" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
    </input>
    <output>
      <soap:body use="encoded" namespace="urn:my:services" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
    </output>
  </operation>
</binding>

<service name="MyServices">
  <port name="ServicesPort" binding="tns:ServicesBinding">
    <soap:address location="http://mydomain.com/api/soap/v11/services"/>
  </port>
</service>
</definitions>

I can successfully generate a proxy class from this WSDL in Visual Studio, but upon trying to invoke the getServices method I am presented with an exception:

我可以在Visual Studio中成功地从这个WSDL生成一个代理类,但是在尝试调用getServices方法时,我遇到了一个异常:

System.Web.Services.Protocols.SoapHeaderException: Procedure 'string' not present

System.Web.Services.Protocols。SoapHeaderException:不存在的过程字符串。

After inspecting the raw post data at the SOAP server end, my PHP SOAP client is making requests like this:

在SOAP服务器端检查原始post数据之后,我的PHP SOAP客户机发出如下请求:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" 
    SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body>
        <postcode xsi:type="xsd:string">ln4 4nq</postcode>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Whereas the .Net proxy class is doing this:

而。net代理类则是这样做的:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
    xmlns:tns="http://mydomain.com/api/soap/v11/services" 
    xmlns:types="http://mydomain.com/api/soap/v11/services/encodedTypes" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
        <xsd:string xsi:type="xsd:string">LN4 4NQ</xsd:string>
    </soap:Body>
</soap:Envelope>

I can only assume the difference in the way the postcode parameter is being sent is where the problem lies, but as primarily a PHP developer I'm at a loss as to what's occuring here. I have a feeling I'm simply missing something vital in my WSDL as I've seen countless examples of 'Consuming PHP SOAP WebServices with .Net' which appear to suggest that it 'just works'.

我只能假设发送postcode参数的方式不同是问题所在,但作为PHP开发人员,我对这里发生的事情感到困惑。我有一种感觉,我只是在WSDL中忽略了一些重要的东西,因为我看到了无数“使用。net的PHP SOAP WebServices”的例子,这似乎表明它“只是工作”。

Any suggestion as to where i've slipped up here would be greatly appreciated. I've currently spent almost an entire day on this now ;-)

对于我在这里疏忽的任何建议,都将不胜感激。我现在已经花了差不多一整天在这上面了;-)

Thanks in advance,

提前谢谢,

Jamie

杰米

2 个解决方案

#1


1  

Sorry to make an answer instead of a comment by I don't have enough reputation for that yet...

很抱歉,我没有足够的声誉来回答这个问题。

You should try to test your webservice with SOAP-UI (they have a free version), so you'll know if the problem is client side or server side.

您应该尝试使用SOAP-UI测试您的web服务(它们有一个免费版本),这样您就会知道问题是客户端还是服务器端。

#2


0  

The WSDL has errors, therefore most probably the proxy class is corrupt. So is the request.
WSDL is very complex to do right unless you use a good WSDL editor. I would sugget Eclipse WSDL editor (http://wiki.eclipse.org/index.php/Introduction_to_the_WSDL_Editor)

(1) The {max occurs} of an element in an 'all' model group must be 0 or 1. The value '-1' for element 'Services' is invalid.
(2) Error resolving component 'ServiceType'. It was detected that 'ServiceType' is in namespace 'http://www.w3.org/2001/XMLSchema', but components from this namespace are not referenceable from schema document

WSDL有错误,因此代理类很可能是损坏的。所以请求。除非您使用一个好的WSDL编辑器,否则WSDL是非常复杂的。我将sugget Eclipse WSDL编辑器(http://wiki.eclipse.org/index.php/tion_to_the_wsdl_editor)(1)“所有”模型组中元素的{max}都必须是0或1。元素“服务”的值“-1”是无效的。(2)错误解析组件的ServiceType。检测到“ServiceType”位于名称空间“http://www.w3.org/2001/XMLSchema”中,但是来自该名称空间的组件不能从模式文档引用

#1


1  

Sorry to make an answer instead of a comment by I don't have enough reputation for that yet...

很抱歉,我没有足够的声誉来回答这个问题。

You should try to test your webservice with SOAP-UI (they have a free version), so you'll know if the problem is client side or server side.

您应该尝试使用SOAP-UI测试您的web服务(它们有一个免费版本),这样您就会知道问题是客户端还是服务器端。

#2


0  

The WSDL has errors, therefore most probably the proxy class is corrupt. So is the request.
WSDL is very complex to do right unless you use a good WSDL editor. I would sugget Eclipse WSDL editor (http://wiki.eclipse.org/index.php/Introduction_to_the_WSDL_Editor)

(1) The {max occurs} of an element in an 'all' model group must be 0 or 1. The value '-1' for element 'Services' is invalid.
(2) Error resolving component 'ServiceType'. It was detected that 'ServiceType' is in namespace 'http://www.w3.org/2001/XMLSchema', but components from this namespace are not referenceable from schema document

WSDL有错误,因此代理类很可能是损坏的。所以请求。除非您使用一个好的WSDL编辑器,否则WSDL是非常复杂的。我将sugget Eclipse WSDL编辑器(http://wiki.eclipse.org/index.php/tion_to_the_wsdl_editor)(1)“所有”模型组中元素的{max}都必须是0或1。元素“服务”的值“-1”是无效的。(2)错误解析组件的ServiceType。检测到“ServiceType”位于名称空间“http://www.w3.org/2001/XMLSchema”中,但是来自该名称空间的组件不能从模式文档引用