Take the 2-minute tour ×

I am trying to send multiple repeated elements via a Soap Call. I tried building an array and sending, but it would process only the first element. The following post was helpful as I adapted the code using SoapVar SoapVar/Param and nested, repeated elements in SOAP. The issue that I am facing now, however, is that when I try to send off my soap request, the soap call needs the request as an array, and the following code gets a failure from the soap server. The WSDL file I am working with is at https://ecomapi.networksolutions.com/soapservice.asmx?wsdl

I have replaced the header elements for security (my name, my cert number, my token) - but other than that, the complete code is below. Any thoughts on what I am doing wrong here?


$ns = 'urn:networksolutions:apis';
$header->Application = 'my name';
$header->Certificate = 'my cert number';
$header->UserToken = 'my token';

$credentials = new SOAPHeader($ns, "SecurityCredential", $header);

$client = new SoapClient('https://ecomapi.networksolutions.com/soapservice.asmx?wsdl',
                array('soap_version' => SOAP_1_1 ,
                                'trace' => 1));
 $array1[]=new SoapVar("9",XSD_STRING,null,null,'ProductId');
 $array1[]=new SoapVar("500",XSD_STRING,null,null,'QtyInStock');
 $soap1 = new SoapVar($array1, SOAP_ENC_OBJECT, null, null, "Inventory");
 $interim = array($soap1);
 $test = array();
 $test[] = new SoapVar($interim, SOAP_ENC_OBJECT, null, null, "UpdateInventoryRequestList");

 $array2[]=new SoapVar("10",XSD_STRING,null,null,'ProductId');
 $soap2 = new SoapVar($array2, SOAP_ENC_OBJECT, null, null, "Inventory");
 $interim2 = array($soap2);
 $test[] = new SoapVar($interim2, SOAP_ENC_OBJECT, null, null, "UpdateInventoryRequestList");

 $submit1 = array($test);
 $submit = new SoapVar($submit1, SOAP_ENC_OBJECT, null, null, "PerformMultipleRequest");
 $final_submit = array($submit);

 $result = $client->__soapCall("PerformMultiple", $final_submit, NULL, $credentials);

 echo "REQUEST:\n" . $client->__getLastRequest() . "\n";   // gets last SOAP request
 echo "RESPONSE:\n" . $client->__getLastResponse() . "\n"; // gets last SOAP respone

share|improve this question

1 Answer 1

Why so complicated?

PHPs SoapClient does all that stuff automatically for you:

$array = array();
$array[] = new Inventory(50, 100);
$array[] = new Inventory(51, 10);
                array('soap_version' => SOAP_1_1, 'trace' => 1));

The Inventory needs to be something like:

class Inventory
    public $ProductId;
    public $QtyInStock;

    public function __construct($id, $qty)
        $this->ProductId = $id;
        $this->QtyInStock = $qty;

I'm using many Soap-Services that way. Only the other way around it is a little tricky, because parameters as arrays are not directly accessible, e.g if you expect $param to be ObjectClass[] you get that array from $param->ObjectClass.


share|improve this answer
Ah thanks. I thought I wouldn't need to use SoapVar but I just couldn't get it to work! This is the first time I've used Stack Overflow - I should have come here earlier - I really appreciate your help. –  Hayden Jun 8 '11 at 18:06

Your Answer


