Complex Calls With Soap Client

I've just started using the SOAP Client module in Drupal to handle SOAP requests. It's a great little tool. If you set it to use the nuSOAP PHP libraries (instead of core) it even handles Microsoft datasets, which some Microsoft-based web services will return.

There is one small problem. Documentation is approximately zero! The only assistance offered is "look at the code of the admin test form", which is great for simple name/value pairs of data, but doesn't tackle complex types.

SOAP Client works much like the XML-RPC client which is core to Drupal. You build an array of parameters and pass them to a function which wraps them in a SOAP envelope and passes them on to the web service, then handles the returned result. But what happens if you have a structure like this?

<requiredMortgageRateTypes>
  <MortgageRateTypeEnum>Variable</MortgageRateTypeEnum>
  <MortgageRateTypeEnum>Fixed</MortgageRateTypeEnum>
</requiredMortgageRateTypes>

Of course arrays cannot have duplicate keys. We would have to pass the following in PHP to send these parameters:

<?php
array(
 
'requiredMortgageRateTypes' => array(
   
'MortgageRateTypeEnum' => 'Variable',
   
'MortgageRateTypeEnum' => 'Fixed',
  ),
);
?>

Which is illegal, so we can't. The answer is the code below. This is how you deal with multiple values in the same XML tag using Drupal SOAP Client:

<?php
array(
 
'requiredMortgageRateTypes' => array(
   
'MortgageRateTypeEnum' => array(
     
'Variable',
     
'Fixed',
    ),
  ),
);
?>

Post new Comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.