无法序列化,因为它没有无参数构造函数soap客户端php

时间:2012-04-17 04:06:08

标签: php soap

我尝试使用php soap client从webservice中提取数据, 但我得到了肥皂故障

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>";
  ?>

有关api的文档可以在http://www.ozsale.com.au/API/V2/api.asmx?op=GetPublicSalesBanners

找到

有人知道这里有什么问题吗?是我的代码还是webservice的问题?

2 个答案:

答案 0 :(得分:1)

看起来他们的结局是错误的。我刚刚运行soapUI来尝试它并得到完全相同的错误。

此外,错误似乎是一个ASP错误(服务器端),而不是PHP错误(客户端 - 你自己)。

联系他们的支持(假设他们有支持)。

修改 此外,我只是在使用其他公开方法之一GetPublicSalesCategories,只需countryIDlangaugeID并使用AS,因为国家/地区生成了与之前相同的错误。但是,如果我将countryID更改为AUUS我就不会收到错误(我没有获得任何有用的数据,但它是<result>true</result>响应

您的AS国家/地区代码可能无效?

答案 1 :(得分:0)

关于System.StringSystem.Object的内容看起来很像.NET错误,可能在服务器端(不是你的错)。