2012-04-17 26 views
0

我試圖使用PHP SOAP客戶端, 拉從web服務數據,但我得到了SOAP錯誤不能序列化,因爲它不具有無參數的構造函數SOAP客戶端PHP

SoapFault Object (
    [message:protected] => Server was unable to process request. ---> There was an error generating the XML document. ---> <>f__AnonymousType2a`2[System.String,System.Object[]] cannot be serialized because it does not have a parameterless constructor. 
    [string:Exception:private] => 
     [code:protected] => 0 
     [file:protected] => /Users/resarahman/Documents/xampp/htdocs/testing/soap/test.php 
     [line:protected] => 17 
     [trace:Exception:private] => Array ( 
      [0] => Array ( 
       [file] => /Users/resarahman/Documents/xampp/htdocs/testing/soap/test.php 
       [line] => 17 
       [function] => __call 
       [class] => SoapClient 
       [type] => -> 
       [args] => Array ( 
        [0] => GetPublicSalesBanners 
        [1] => Array ( 
         [0] => Array ( 
          [saleCategoryID] => 40F80218-A9E1-43C4-96FF-4C046D192A21 
          [countryID] => AS 
          [languageID] => EN 
          [getTopThree] => 1 
         ) 
        ) 
       ) 
      ) 
      [1] => Array ( 
       [file] => /Users/resarahman/Documents/xampp/htdocs/testing/soap/test.php 
       [line] => 17 
       [function] => GetPublicSalesBanners 
       [class] => SoapClient 
       [type] => -> 
       [args] => Array ( 
        [0] => Array ( 
         [saleCategoryID] => 40F80218-A9E1-43C4-96FF-4C046D192A21 
         [countryID] => AS 
         [languageID] => EN 
         [getTopThree] => 1 
        ) 
       ) 
      ) 
     ) 
     [previous:Exception:private] => 
     [faultstring] => Server was unable to process request. ---> There was an error generating the XML document. ---> <>f__AnonymousType2a`2[System.String,System.Object[]] cannot be serialized because it does not have a parameterless constructor. 
     [faultcode] => soap:Server 
     [detail] =>) 

請求和響應

要求:

<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://ws.ozsale.com.au/API/V2"> 
    <SOAP-ENV:Body> 
     <ns1:GetPublicSalesBanners> 
      <ns1:saleCategoryID>40F80218-A9E1-43C4-96FF-4C046D192A21</ns1:saleCategoryID> 
      <ns1:countryID>AS</ns1:countryID> 
      <ns1:languageID>EN</ns1:languageID> 
      <ns1:getTopThree>true</ns1:getTopThree> 
     </ns1:GetPublicSalesBanners> 
    </SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

響應:

<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <soap:Body> 
     <soap:Fault> 
      <faultcode>soap:Server</faultcode> 
      <faultstring>Server was unable to process request. ---&gt; There was an error generating the XML document. ---&gt; &lt;&gt;f__AnonymousType2a`2[System.String,System.Object[]] cannot be serialized because it does not have a parameterless constructor.</faultstring> 
      <detail /> 
     </soap:Fault> 
    </soap:Body> 
</soap:Envelope> 

這裏我到目前爲止的代碼:

<?php 
// create a connection to the local host mono .NET pull back the wsdl to get the functions names 
    // and also the parameters and return values 
    $client = new SoapClient("http://www.ozsale.com.au/api/v2/api.asmx?WSDL", 
    array(
     "trace"  => 1, // enable trace to view what is happening 
     "exceptions" => 0, // disable exceptions 
     "cache_wsdl" => 0) 
); 

    // get a response from the WSDL zend server function getQuote for the day monday 
    $data = $client->GetPublicSalesBanners(array(
    'saleCategoryID' => '40F80218-A9E1-43C4-96FF-4C046D192A21', 
    'countryID'=> 'AS', 
    'languageID'=> 'EN', 
    'getTopThree' =>'1' 
)); 

    print_r($data); 

    // display what was sent to the server (the request) 
    echo "<p>Request :".htmlspecialchars($client->__getLastRequest()) ."</p>"; 
    // display the response from the server 
    echo "<p>Response:".htmlspecialchars($client->__getLastResponse())."</p>"; 
    ?> 

Documentasi有關API可以在這裏找到http://www.ozsale.com.au/API/V2/api.asmx?op=GetPublicSalesBanners

任何人都知道這裏有什麼問題?是我的代碼還是它是一個web服務的問題?

+0

感謝@Blair,我沒有得到格式化的權利 – zanlok 2012-04-17 04:45:12

回答

0

關於System.StringSystem.Object的東西看起來像.NET錯誤的可疑,並可能在服務器端(不是你的錯)。

+0

而且,它看起來並不像你本身傳遞了一個錯誤的值。是否有另一個函數可以測試 - 比如 - > GetOrderList()或者我在WSDL中看到的其他函數? – zanlok 2012-04-17 04:49:44

1

看起來這是他們的錯誤。我剛剛運行soapUI在那裏嘗試,並得到了完全相同的錯誤。

此外,錯誤似乎是一個ASP錯誤(服務器端),而不是一個PHP錯誤(客戶端 - 你的)。

聯繫他們的支持(假設他們有一個)。

編輯: 此外,我只是用自己的其他公共方法GetPublicSalesCategories只需要countryIDlangaugeID一個玩弄和利用AS作爲該國之前產生了同樣的錯誤。但是,如果我改變countryIDAUUS我沒有得到一個錯誤(我沒有得到任何有用的數據,但它是一個<result>true</result>響應。

也許AS國家代碼是無效的?

相關問題