tags:

views:

43

answers:

1

I am trying to generate a SOAP XML request that looks something like this:

<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>

I get a response using this code:

    $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"; 
} 

but if I try to array the fielddto item like this:

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

It wraps each item in it's own FieldDTO tag instead of placing all four items in a single FieldDTO tag.

What am I missing? It seems like it should work, but it's not quite right.

+1  A: 

Note that every time you execute $matchCompany->FieldList->FieldDTO[]['any_field'] the index of the array is increased by one. You could use a defined and manually incremented index (e.g. $matchCompany->FieldList->FieldDTO[$i]['any_field'] = 'any_value') or simply set all the values at once:

$matchCompany->FieldList->FieldDTO[] = array(
    'fieldType' => 'GENERAL',
    'label' => 'Business Name',
    'name' => 'BizInfo-BusinessName',
    'index' => '0'
);
nuqqsa
Perfect. Thanks much. I would vote, but I'm too new to vote this the right answer.
Kevin Miles
@Kevin You may not be able to vote up but you should be able to click the check mark right under the up/down arrows.
Samuel