加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

使用ASP.NET的PHP SOAP WebService

发布时间:2020-12-16 07:42:59 所属栏目:asp.Net 来源:网络整理
导读:我在使用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"
我在使用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>

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

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

在SOAP服务器端检查原始发布数据后,我的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>

而.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>

我只能假设邮政编码参数发送方式的不同之处在于问题所在,但主要是PHP开发人员,我不知道这里发生了什么.我有一种感觉,我只是遗漏了一些在我的WSDL中至关重要的东西,因为我看过无数的“使用.Net消费PHP SOAP Web服务”的例子,似乎表明它“只是有效”.

关于我在哪里滑倒的任何建议将不胜感激.我现在已经花了差不多一整天了;-)

提前致谢,

杰米

解决方法

很抱歉找到答案而不是评论我还没有足够的声誉……

您应该尝试使用SOAP-UI测试您的Web服务(它们有免费版本),因此您将知道问题是客户端还是服务器端.

(编辑:李大同)

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

    推荐文章
      热点阅读