2011-04-12 110 views
3

我正在尝试使用Yii来提供Web服务。自动生成的wsdl在下面。我可以成功地消耗在命令行中的Web服务,而是通过Web浏览器,我得到SOAP-ERROR:编码:违反编码规则?

SOAP-ERROR: Encoding: Violation of encoding rules 

我是新来的SOAP,所以我不知道如何调试问题。下面是我使用使用的Web服务的PHP代码:

<?php 
    $client=new SoapClient('{url omitted for security}', 
     array('trace'=>1,'exceptions'=>1)); 
    try { 
     $result = $client->getPerson(90043412); 
     var_dump($result); 
    } catch (SoapFault $fault) { 
     echo $fault->getMessage() . '<br />'; 
     echo 'REQUEST <br />'; 
     echo '<pre>'; 
     echo $client->__getLastRequestHeaders(); 
     echo $client->__getLastRequest(); 
     echo '</pre>'; 
     echo 'RESPONSE <br />'; 
     echo '<pre>'; 
     echo $client->__getLastResponseHeaders(); 
     echo $client->__getLastResponse(); 
     echo '</pre>'; 
     echo 'TRACE <br />'; 
     echo '<pre>'; 
     var_dump($fault->getTrace()); 
     echo '</pre>'; 
    } 
?> 

这里是WSDL:

<?xml version="1.0" encoding="UTF-8"?> 
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="urn:PersonControllerwsdl" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" name="PersonController" targetNamespace="urn:PersonControllerwsdl"> 
    <wsdl:types> 
     <xsd:schema targetNamespace="urn:PersonControllerwsdl"> 
      <xsd:complexType name="Person"> 
       <xsd:all> 
        <xsd:element name="PIDM" type="xsd:integer"/> 
        <xsd:element name="FirstName" type="xsd:string"/> 
        <xsd:element name="MiddleName" type="xsd:string"/> 
        <xsd:element name="LastName" type="xsd:string"/> 
        <xsd:element name="PrefFirstName" type="xsd:string"/> 
        <xsd:element name="CPOBox" type="xsd:string"/> 
        <xsd:element name="Classification" type="xsd:string"/> 
        <xsd:element name="Email" type="xsd:string"/> 
        <xsd:element name="PhotoFile" type="xsd:string"/> 
       </xsd:all> 
      </xsd:complexType> 
     </xsd:schema> 
    </wsdl:types> 
    <wsdl:message name="getPersonRequest"> 
     <wsdl:part name="PIDM" type="xsd:int"/> 
    </wsdl:message> 
    <wsdl:message name="getPersonResponse"> 
     <wsdl:part name="return" type="tns:Person"/> 
    </wsdl:message> 
    <wsdl:portType name="PersonControllerPortType"> 
     <wsdl:operation name="getPerson"> 
      <wsdl:documentation></wsdl:documentation> 
      <wsdl:input message="tns:getPersonRequest"/> 
      <wsdl:output message="tns:getPersonResponse"/> 
     </wsdl:operation> 
    </wsdl:portType> 
    <wsdl:binding name="PersonControllerBinding" type="tns:PersonControllerPortType"> 
     <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> 
     <wsdl:operation name="getPerson"> 
      <soap:operation soapAction="urn:PersonControllerwsdl#getPerson" style="rpc"/> 
      <wsdl:input> 
       <soap:body use="encoded" namespace="urn:PersonControllerwsdl" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> 
      </wsdl:input> 
      <wsdl:output> 
       <soap:body use="encoded" namespace="urn:PersonControllerwsdl" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> 
      </wsdl:output> 
     </wsdl:operation> 
    </wsdl:binding> 
    <wsdl:service name="PersonControllerService"> 
     <wsdl:port name="PersonControllerPort" binding="tns:PersonControllerBinding"> 
      <soap:address location="https://localhost/whoswho/person/service?ws=1"/> 
     </wsdl:port> 
    </wsdl:service> 
</definitions> 
+0

我正在使用我用来使用Web服务的相同框中的Web服务。如果我在上面托管上面的php脚本,它会成功使用Web服务。我是否遇到浏览器问题? – nhavens 2011-04-12 17:14:21

+0

托管和使用Web服务的每个其他组合都可以使用。也许这个问题是特定于托管一个Web服务,并使用XAMPP for linux v1.7.3a和1.8在同一个盒子上通过Web浏览器使用它。我知道这听起来很奇怪,但我无法让消费脚本打破任何其他方式。 – nhavens 2011-04-13 01:06:16

回答

1

如果我是主持人在不同的服务器比一个承载Web服务上的消费脚本,它的功能正常。由于Web服务专为机器通信而设计,而不仅仅是一台机器与自身交谈,所以这似乎是一个适当的解决方案。

4

有可能是SOAP请求的格式不正确。我一直在使用SoapUI,默认情况下所有参数都设置为'?'最初,如果你提出这个请求,PHP将会失败,并回应你所报告的错误信息。你无法理解这一点,因为没有抛出异常,这是因为它是一个致命的错误。

可以使用的set_error_han dler()函数http://php.net/manual/en/function.set-error-handler.php

1

我知道这是一个古老的线程设置自己的错误处理针对这种情况,但如果你遇到它,因为我也想弄清楚这个问题,你可能会尝试将soap:地址设置为http://127.0.0.1而不是http://localhost。我遇到了一些其他的论坛,在这方面有所帮助。

+0

对我来说,这是由于配置错误,但你的答案让我意识到它是配置。 +1。 – aggregate1166877 2012-08-14 08:10:38

1

我正在努力将我的PHP版本更新到5.6.26,并在我的Web服务调用中弹出此错误消息。过了一会儿,我发现问题可以固定在php.ini文件中这一行注释:

;always_populate_raw_post_data = -1 

查看文档,此选项在此版本中已过时。

我希望这个评论可以节省时间给别人。