php5 SOAP客户端开发相同的标签

时间:2010-05-06 19:29:22

标签: php xml soap

我正在尝试生成一个类似于这样的SOAP XML请求:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dto="dto" xmlns:com="">
   <soapenv:Header>
      <dto:AuthenticationDTO>
     <dto:LOGIN_ID>login</dto:LOGIN_ID>
     <dto:LOGIN_PASSWORD>login</dto:LOGIN_PASSWORD>
  </dto:AuthenticationDTO>
   </soapenv:Header>
   <soapenv:Body>
  <com:createAccount>
     <com:AccountFields>
        <!--Zero or more repetitions:-->
        <dto:FieldDTO>
           <!--Optional:-->
           <dto:children/>
           <!--Optional:-->
           <dto:fieldType>GENERAL</dto:fieldType>
           <!--Optional:-->
           <dto:index>0</dto:index>
           <!--Optional:-->
           <dto:label>BusinessName</dto:label>
           <!--Optional:-->
           <dto:name>BizInfo-BusinessName</dto:name>
           <!--Optional:-->
           <dto:value>the business name</dto:value>
        </dto:FieldDTO>
        <!--Zero or more repetitions:-->
        <dto:FieldDTO>
           <!--Optional:-->
           <dto:children/>
           <!--Optional:-->
           <dto:fieldType>GENERAL</dto:fieldType>
           <!--Optional:-->
           <dto:index>0</dto:index>
           <!--Optional:-->
           <dto:label>BusinessCountry</dto:label>
           <!--Optional:-->
           <dto:name>BizInfo-Country</dto:name>
           <!--Optional:-->
           <dto:value>US</dto:value>
        </dto:FieldDTO>
     </com:AccountFields>
     <com:ApplicationNumber></com:ApplicationNumber>
     <com:CreditTerms></com:CreditTerms>
     <com:GenerateAccountIdIndicator>true</com:GenerateAccountIdIndicator>
  </com:createAccount>

我使用此代码得到回复:

    $matchCompany->FieldList->FieldDTO->fieldType = 'GENERAL';
    $matchCompany->FieldList->FieldDTO->label = 'Business Name';
    $matchCompany->FieldList->FieldDTO->name = 'BizInfo-BusinessName';
    $matchCompany->FieldList->FieldDTO->index = '0';
try
{  
    $result = $soapClient->getAccountInfo($matchCompany);     
    print "<pre>";
    print_r($result); 
    print "</pre>";
    echo "REQUEST:\n" . htmlentities($soapClient->__getLastRequest()) . "\n"; 

}
catch(SoapFault $fault)
{  
   echo $fault->faultcode . "-" . $fault->faultstring;  
   echo "REQUEST:\n" . htmlentities($soapClient->__getLastRequest()) . "\n"; 
} 

但是,如果我尝试将fielddto数组像这样:

    //$matchCompany->FieldList->FieldDTO[]['fieldType'] = 'GENERAL';
//$matchCompany->FieldList->FieldDTO[]['label'] = 'Business Name';
//$matchCompany->FieldList->FieldDTO[]['name'] = 'BizInfo-BusinessName';
//$matchCompany->FieldList->FieldDTO[]['index'] = '0';

它将每个项目包装在自己的FieldDTO标记中,而不是将所有四个项目放在一个FieldDTO标记中。

我错过了什么?它似乎应该有效,但它不太正确。

1 个答案:

答案 0 :(得分:2)

请注意,每次执行$matchCompany->FieldList->FieldDTO[]['any_field']时,数组的索引都会增加1。您可以使用已定义和手动递增的索引(例如$matchCompany->FieldList->FieldDTO[$i]['any_field'] = 'any_value')或只是一次性设置所有值:

$matchCompany->FieldList->FieldDTO[] = array(
    'fieldType' => 'GENERAL',
    'label' => 'Business Name',
    'name' => 'BizInfo-BusinessName',
    'index' => '0'
);