2011-04-12 77 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 

查看文檔,此選項在此版本中已過時。

我希望這個評論可以節省時間給別人。