Recipe 14.5. Using Complex SOAP Types

14.5.1. Problem

You need to pass data structures more complicated than strings, integers, and other simple types. Instead, you need to pass arrays and objects.

14.5.2. Solution

Pass the data as an associative array:

 $args = array('ticker' => array('EBAY', 'YHOO', 'GOOG')); $client->getQuotes($args); 

14.5.3. Discussion

It can be tricky figuring out how to map PHP data structures into the XML that's described in the WSDL'especially since the premise of SOAP is that general consumers of a SOAP service shouldn't be worrying about the underlying XML .

The ext/soap extension does a pretty good job of doing the right thing of properly converting data. However, sometimes you need to get down and dirty and read the WSDL yourself, or see if the service publishes a few SOAP examples that reveal the XML that it's expecting.

As a rule of thumb, when you're expected to pass multiple elements of the same name at the same level, such as:

<ticker>EBAY</ticker> <ticker>YHOO</ticker> <ticker>GOOG</ticker>

You should define an array containing a key of ticker and a value of another array. This array should contain the data that needs to get wrapped around <ticker> tags.

14.5.4. See Also

Recipe 14.6 for setting SOAP types.

PHP Cookbook, 2nd Edition
PHP Cookbook: Solutions and Examples for PHP Programmers
ISBN: 0596101015
EAN: 2147483647
Year: 2006
Pages: 445

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: