PHP SoapClient XML对象没有' xxx'属性

时间:2016-05-04 01:48:58

标签: php xml soap nusoap

我尝试使用PHP的SoapClient类创建消息,但是我在创建请求时遇到了问题。任何帮助将不胜感激,我无法在Google或SO上找到有关此特定类型的XML格式的任何内容,甚至是它的名称。

我的问题是创建"<stan:Param id="Main.StreetNumber">20</stan:Param>"行。 有没有人知道如何正确格式化?我得到的错误是:

  

PHP致命错误:SOAP-ERROR:编码:对象没有&#39;&#39; Param&#39;属性   在第112行的/var/www/html/dev/M2Testing/class-m2-interface.php

目标XML:

<soapenv:Body>
<whol:GetRequest>
    <whol:AccessKey>fakeaccesskey</whol:AccessKey>
    <whol:ProductID>fakeproductid</whol:ProductID>
    <whol:PlanID>fakeplanid</whol:PlanID>
    <whol:Scope>fakescope</whol:Scope>
    <whol:Parameters>
        <stan:Param id="Main.StreetNumber">20</stan:Param>
        etc...
    </whol:Parameters>
</whol:GetRequest>
</soapenv:Body>

我目前的代码是:

$options = array(
        'trace'         => true,
        'cache_wsdl'    => WSDL_CACHE_NONE
    );            

    $params = array(
      'AccessKey' => 'myfakeaccesskey',
      'ProductID' => 'fakeproductid',
      'PlanID' => 'fakeplanid',
      'Scope' => 'fakescope',
      'Parameters' => array(
          'Main.Street1stNumber' => '20',
          'Main.StreetName' => 'Street',
          'Main.StreetType' => 'Street',
          'Main.Suburb' => 'Suburb',
          'Main.State' => 'State',
          )
    );
    $client = new SoapClient(interface::SOAP_WSDL, $options);
    try {
        $result = $client->Get($params);
        echo "Success?";
    }
    catch(Exception $e)
    {
        echo $e;
        var_dump($client->__getLastRequest());
    }

这些是WSDL的相关部分:

<complexType name="GetRequest">
<sequence>
    <element name="AccessKey" type="std:AccessKey"
        maxOccurs="1" minOccurs="1">
    </element>
    <element name="AliasKey" type="std:AliasKey"
        maxOccurs="1" minOccurs="0">
    </element>              
    <element name="ProductID" type="std:ProductID"
        maxOccurs="1" minOccurs="1">
    </element>
    <element name="PlanID" type="std:PlanID" maxOccurs="1"
        minOccurs="0">
    </element>
    <element name="Scope" type="std:Scope" maxOccurs="1"
        minOccurs="0">
    </element>
    <element name="Parameters" type="std:Parameters"
        maxOccurs="1" minOccurs="0">
    </element>
</sequence>

<complexType name="Param">
<simpleContent>
    <extension base="string">
        <attribute name="id" type="string"></attribute>
    </extension>
</simpleContent>

<complexType name="Parameters">
<sequence>
    <element name="Param" type="tns:Param" maxOccurs="unbounded"
        minOccurs="1" />
</sequence>

0 个答案:

没有答案