你调用的对象是空的。请查看我的代码

时间:2012-04-13 08:47:17

标签: php soap

我对肥皂的使用并不熟悉。 我想从soap服务器中提取数据,但似乎存在问题(对象引用未设置为对象的实例。)。 这是我代码中的调试代码:

stdClass Object ( [GetSalesBannersResult] => stdClass Object ( [Result] => [Message] => Object reference not set to an instance of an object. [List] => stdClass Object ( ) ) )
Request :<?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:GetSalesBanners><ns1:saleCategoryID>40F80218-A9E1-43C4-96FF-4C046D192A21</ns1:saleCategoryID><ns1:getTopThree>true</ns1:getTopThree></ns1:GetSalesBanners></SOAP-ENV:Body></SOAP-ENV:Envelope>

Response:<?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><GetSalesBannersResponse xmlns="http://ws.ozsale.com.au/API/V2"><GetSalesBannersResult><Result>false</Result><Message>Object reference not set to an instance of an object.</Message><List /></GetSalesBannersResult></GetSalesBannersResponse></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
  print_r($client->GetSalesBanners(array(
    "saleCategoryID" => "40F80218-A9E1-43C4-96FF-4C046D192A21", 
    "getTopThree" =>"1"
    ))
  );
  //print_r($client);

  // 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=GetSalesBanners

任何人都可以帮助弄清楚这里有什么问题......


我的问题的新更新。现在文档api在这里http://www.ozsale.com.au/api/v2/api.asmx?op=GetPublicSalesBanners

我尝试使用以下信息提取数据:

'saleCategoryID' => '40F80218-A9E1-43C4-96FF-4C046D192A21',
'countryID'=> 'AS',
'languageID'=> 'EN', 
'getTopThree' =>'1'

我的代码在这里:

<?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
  print_r($client->GetPublicSalesBanners(array(
    'saleCategoryID' => '40F80218-A9E1-43C4-96FF-4C046D192A21',
    'countryID'=> 'AS',
    'languageID'=> 'EN', 
    'getTopThree' =>'1'
    ))
  );

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

当我试图看它是如何工作时,它的输出如下:

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] => )
Request :<?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>

Response:<?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>

知道为什么以及出了什么问题?

1 个答案:

答案 0 :(得分:1)

您的输入看起来没问题,除非有任何特殊要求,例如SOAP标头。这很可能是提供商需要修复的Web服务的问题,而不是客户端代码的问题。我建议联系他们。