tags:

views:

28

answers:

3

I am having a problem with a soap call I'm trying to do from PHP.

First some background information: The call is going to a system that does a person search on a big CRM system. It requires information like name, city, birthdate, etc. ) When successful, it should return one or multiple id's. The soap interface is a standard piece of the system, so I can not influence the layout of the call.

I first started off by building the soap request in SoapUI, to see if I could get it working. I ended up with this soap request, which is working:

 <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:hidl="http://humaninference.com/hidl-mapped"&gt;
   <soap:Header/>
   <soap:Body>
      <hidl:HI__DQComponents__Identify__Searching__Search>
         <hidl:model>MAGMA::PERSON</hidl:model>
         <hidl:execution>Match</hidl:execution>
         <hidl:interfaceFields>
            <hidl:item>
               <hidl:Name>master_id</hidl:Name>
               <hidl:Value>0</hidl:Value>
            </hidl:item>
            <hidl:item>
               <hidl:Name>Name</hidl:Name>
               <hidl:Value>jansen</hidl:Value>
            </hidl:item>
            <hidl:item>
               <hidl:Name>birthdate</hidl:Name>
               <hidl:Value></hidl:Value>
            </hidl:item>
            <hidl:item>
               <hidl:Name>add_id</hidl:Name>
               <hidl:Value></hidl:Value>
            </hidl:item>
            <hidl:item>
               <hidl:Name>street</hidl:Name>
               <hidl:Value>oudegracht</hidl:Value>
            </hidl:item>
            <hidl:item>
               <hidl:Name>dumstreet</hidl:Name>
               <hidl:Value></hidl:Value>
            </hidl:item>
            <hidl:item>
               <hidl:Name>housenumber</hidl:Name>
               <hidl:Value></hidl:Value>
            </hidl:item>
            <hidl:item>
               <hidl:Name>postcode</hidl:Name>
               <hidl:Value></hidl:Value>
            </hidl:item>
        <hidl:item>
               <hidl:Name>city</hidl:Name>
               <hidl:Value>Utrecht</hidl:Value>
            </hidl:item>
        <hidl:item>
               <hidl:Name>citydum</hidl:Name>
               <hidl:Value></hidl:Value>
            </hidl:item>
        <hidl:item>
               <hidl:Name>add_line_twee</hidl:Name>
               <hidl:Value></hidl:Value>
            </hidl:item>
         </hidl:interfaceFields>
      </hidl:HI__DQComponents__Identify__Searching__Search>
   </soap:Body>
</soap:Envelope>

The next step was to build the same request from PHP, for that I wrote this piece of code:

$result = $client->HI__DQComponents__Identify__Searching__Search(array(
    'model' => 'MAGMA::PERSON', 
    'execution' => 'Search',
    'interfaceFields' => array (
        'item' => array ('Name' => 'master_id',     'Value' => '0' ),
        'item' => array ('Name' => 'Name',          'Value' => 'jansen' ),
        'item' => array ('Name' => 'birthdate',     'Value' => ' ' ),
        'item' => array ('Name' => 'add_id',        'Value' => ' ' ),
        'item' => array ('Name' => 'street',        'Value' => 'Oudegracht' ),
        'item' => array ('Name' => 'dumstreet',     'Value' => ' ' ),
        'item' => array ('Name' => 'housenumber',   'Value' => ' ' ),
        'item' => array ('Name' => 'postcode',      'Value' => ' ' ),
        'item' => array ('Name' => 'city',          'Value' => 'utrecht' ),
        'item' => array ('Name' => 'citydum',       'Value' => ' ' ),
        'item' => array ('Name' => 'add_line_twee', 'Value' => ' ' ),
        )
    ));

echo '<PRE>';
print_r($result);
echo '</PRE>';

This however fails. The problem is pretty obvious, since the "item" element is repeated several times, and in PHP it is the key of the array, only the Item add_line_twee will be in the array called "interfaceFields", since it's overwritten all the time.

Unfortunately I can't figure out how to do this another way around, so I can't get the request to be like in the example I created from SoapUI.

Any ideas?

A: 

Could you not use a non-associative array? I.e.

'interfaceFields' => array (
    array ('Name' => 'master_id',     'Value' => '0' ),
    array ('Name' => 'Name',          'Value' => 'jansen' ),
    array ('Name' => 'birthdate',     'Value' => ' ' ),
    array ('Name' => 'add_id',        'Value' => ' ' ),
    array ('Name' => 'street',        'Value' => 'Oudegracht' ),
    array ('Name' => 'dumstreet',     'Value' => ' ' ),
    array ('Name' => 'housenumber',   'Value' => ' ' ),
    array ('Name' => 'postcode',      'Value' => ' ' ),
    array ('Name' => 'city',          'Value' => 'utrecht' ),
    array ('Name' => 'citydum',       'Value' => ' ' ),
    array ('Name' => 'add_line_twee', 'Value' => ' ' ),
)
lonesomeday
Surprisingly, that worked! I thought it wouldn't because i thought the elements named 'Item' would be mandatory, but apparently not. Thanks!
Erikl
A: 

Have you looked at the SoapParam- and SoapVar-objects?

PatrikAkerstrand
A: 

Thanks Patrik, I think you're pointing me in the right way, I now changed the code to:

$result = $client->HI__DQComponents__Identify__Searching__Search(
array(
    'model'  => 'MAGMA::PERSON',
    'execution' => 'Search',
    'interfaceFields' => array (
         new SoapParam(array('Name' => 'master_id',     'Value' => '0')         ,'item'),
         new SoapParam(array('Name' => 'Name',          'Value' => 'jansen')    ,'item'),
         new SoapParam(array('Name' => 'birthdate',     'Value' => ' ')         ,'item'),
         new SoapParam(array('Name' => 'add_id',        'Value' => ' ')         ,'item'),
         new SoapParam(array('Name' => 'street',        'Value' => 'oudegracht'),'item'),
         new SoapParam(array('Name' => 'dumstreet',     'Value' => ' ')         ,'item'),
         new SoapParam(array('Name' => 'housenumber',   'Value' => ' ')         ,'item'),
         new SoapParam(array('Name' => 'postcode',      'Value' => ' ')         ,'item'),
         new SoapParam(array('Name' => 'city',          'Value' => 'Utrecht')   ,'item'),
         new SoapParam(array('Name' => 'citydum',       'Value' => ' ')         ,'item'),
         new SoapParam(array('Name' => 'add_line_twee', 'Value' => ' ')         ,'item'),
        )
    ));

But I think I'm missing the point somewhere, because I now get a error message that the "name" property is not in the call.

Fatal error: Uncaught SoapFault exception: [Sender] SOAP-ERROR: Encoding: object hasn't 'Name' property

I also get the same kind of error when I only change the first line of the call to

new SoapParam('MAGMA::PERSON','model')

So clearly, I'm missing something. Unfortunately, the documentation for the SoapParam isn';t very extensive, so I'm not quite sure what I'm doing wrong here.

Erikl