php soap错误:对象引用未设置为的实例

时间:2016-09-20 04:12:46

标签: php web-services soap

我正在尝试使用此网络服务

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <ABRSearchByName xmlns="http://abr.business.gov.au/ABRXMLSearch/">
      <externalNameSearch>
        <authenticationGUID>string</authenticationGUID>
        <name>string</name>
        <filters>
          <nameType>
            <tradingName>string</tradingName>
            <legalName>string</legalName>
          </nameType>
          <postcode>string</postcode>
          <stateCode>
            <QLD>string</QLD>
            <NT>string</NT>
            <SA>string</SA>
            <WA>string</WA>
            <VIC>string</VIC>
            <ACT>string</ACT>
            <TAS>string</TAS>
            <NSW>string</NSW>
          </stateCode>
        </filters>
      </externalNameSearch>
      <authenticationGuid>string</authenticationGuid>
    </ABRSearchByName>
  </soap:Body>
</soap:Envelope>

下面是我的班级定义

class abnlookup extends SoapClient{

    private $guid = "00000000"; 

    public function __construct($guid)
    {
        $this->guid = $guid;
        $params = array(
            'soap_version' => SOAP_1_1,
            'exceptions' => true,
            'trace' => 1,
            'cache_wsdl' => WSDL_CACHE_NONE
        ); 

        parent::__construct('http://abr.business.gov.au/abrxmlsearch/ABRXMLSearch.asmx?WSDL', $params);
    }

        public function searchByName($name){
            $params = new stdClass();
            $params->name= $name;
            $params->nameType= 'Y' ;
            $params->postcode= 'Y';
            $params->stateCode= 'N' ;           
    $params->authenticationGuid         = $this->guid;
                return $this->ABRSearchByName($params);
}  

调用并创建类对象     $ abnlookup = new abnlookup($ abn_guid);     $ result = $ abnlookup-&gt; searchByName($ name);

并收到此消息 服务器无法处理请求。 ---&GT;对象引用未设置为object.second的实例

1 个答案:

答案 0 :(得分:0)

您传递给ABRSearchByName的$ params结构不正确。根据WSDL,这个结构有两个字段(如__getTypes()所示):

struct ABRSearchByName {
 ExternalRequestNameSearch externalNameSearch;
 string authenticationGuid;
}

使用这两个字段创建$ params,问题应该解决。