SoapClient: how to pass multiple elements with the same name?

I have the following code:

$telnums = array(10, 20, 30); $obj = new StdClass(); $obj->telnums = new StdClass(); foreach ($telnums as $telnum) { $obj->telnums = $telnum; } call_user_func(array($this->client, 'createDomain'), new SoapVar($obj, SOAP_ENC_OBJECT)); 

There $ this-> client is an instance of the SoapClient class.

And it generates the following query:

 <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="..."> <SOAP-ENV:Body> <ns1:createDomain> <createDomainRequest> <telnums>30</telnums> </createDomainRequest> </ns1:createDomain> </SOAP-ENV:Body> </SOAP-ENV:Envelope> 

But i need

  <createDomainRequest> <telnums>10</telnums> <telnums>20</telnums> <telnums>30</telnums> </createDomainRequest> 

How can i achieve this?

PS: PHP 5.2.6-3ubuntu4.5 with Suhosin-Patch 0.9.6.2 (cli) (built: Jan 6, 2010 10:25:33 PM)

Thanks in advance!

+7
soap php soap-client
source share
6 answers

This is fixed by its SoapClient extension and overrides the __doRequest () method, where I change the request as descibed here: http://www.php.net/manual/en/soapclient.dorequest.php#57995

It seems awful to me, but it works "right here, right now."

-one
source share

I recently got into a similar scenario, and I found that this pattern usually does the trick.

 $obj = new StdClass(); foreach ($telnums as $telnum) { $obj->telnums[] = $telnum; } 

The reason for this is that it closely emulates the same data structure as your WSDL

+11
source share

The correct answer should have been:

 $options = array( 'createDomainRequest' => array( 'telnums' => array( '10', '20', '30' ) ) ); 

:)

+8
source share

It’s a pain in the buttock to find a working solution, but in the end it’s not so difficult. Even surprisingly easy and neat using SoapParam's:

 $soapClient = new SoapClient($wsdl); $soapClient->__call('createDomain', array( new SoapParam('10', 'telnums'), new SoapParam('20', 'telnums'), new SoapParam('30', 'telnums'), )); 
+1
source share

Here is the code I used:

 $wsdl = 'https://your.api/path?wsdl'; $client = new SoapClient($wsdl); $multipleSearchValues = [1, 2, 3, 4]; $queryData = ['yourFieldName' => $multipleSearchValues]; $results = $client->YourApiMethod($queryData); print_r($results); 
0
source share
 $telnums=array(10, 20, 30); $createDomainRequest=array('createDomainRequest' => array( 'telnums' => $telnums) ); 
-one
source share

All Articles