Complex Calls With Soap Client

Photo of Greg Harvey
Thu, 2008-10-23 17:11By greg

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?


Variable
Fixed

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

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:

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