SOAP Array items


I’m currently working with PHP’s SOAPClient and a WSDL provided to me by an organisation whose web service we need to use. I’ve made my way down the list no problem until I hit an item that is an array. How on earth do you pass it an array?

Here’s an example piece of code that I was given by the organisation:

<Address xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="__docType_Address[1]">
    <m0:item0 xsi:type="m0:__docType_Address">
        <CoreAddress xsi:type="m0:__docType_CoreAddress">
            <AddressType xsi:type="xsd:string">MAIN</AddressType>
            <BuildingNumber xsi:type="xsd:string"/>
            <BuildingName xsi:type="xsd:string">Building Name</BuildingName>
            <SubBuildingName xsi:type="xsd:string"/>
            <Street1 xsi:type="xsd:string">Street Name</Street1>
            <Street2 xsi:type="xsd:string"/>
            <Locality1 xsi:type="xsd:string">Locality 1</Locality1>
            <Locality2 xsi:type="xsd:string"/>
            <Town xsi:type="xsd:string">Town</Town>
            <County xsi:type="xsd:string"/>
            <Postcode xsi:type="xsd:string">PO57 6DE</Postcode>
            <CountryCode xsi:type="xsd:string"/>
            <OrgName xsi:type="xsd:string"/>
            <DeptName xsi:type="xsd:string"/>
            <POBox xsi:type="xsd:string"/>
            <DeliveryPoint xsi:type="xsd:string"/>
            <ForeignAddress xsi:type="xsd:boolean">0</ForeignAddress>
        <TimeAtAddress xsi:type="m0:__docType_TimeAtAddress">
            <Years xsi:type="xsd:int">3</Years>
            <Months xsi:type="xsd:int">7</Months>

So, in the object that I’m passing to SOAPClient, I’m setting something like:


That doesn’t work at all, I just get no <Address/> at all.

So, I try something like:

$Address = array($Item->CoreAddress->AddressType = ‘MAIN’…

That creates 19 examples of:

<item xsi:type=“ns2:__docType_Address”/>

So, how on earth do I pass these arrays to SOAPClient and have it process it as in the top example?

You;re not actually trying to build the XML structure above are you? :confused:

How do you mean? The example above is a snippet of some existing XML that the organisation provided me. I’m just providing SOAPClient with the parameters and it is building the XML itself via the WSDL. The thing is that we can provide three addresses and they’re “tns:ArrayOf__docType_Address”. I’m trying all sorts of different combinations to try to get it to generate properly. Everything that isn’t an array generates perfectly but everything from this point onwards is an array, so I can’t proceed without working this part out

It looks like a simple array of addresses, try…

$client = new SoapClient('/path/to/wsdl.xml');

$addressCollection = new stdClass();

$addressCollection->Address = array(


To be fair, I spent 9-10 hours looking/working at Soap yesterday and I’m all Soap-ed out!

OK, I think this is right (or at least acceptable)

$ItemA->AddressType       = 'MAIN';
$ItemA->BuildingNumber    = '';
$ItemA->BuildingName      = 'Colloseum';
$ItemA->SubBuildingName   = 'East';
$ItemA->Street1           = 'A Road';
$ItemA->Street2           = '';
$ItemA->Locality1         = 'Rome';
$ItemA->Locality2         = '';
$ItemA->Town              = 'Rome';
$ItemA->County            = 'Rome';
$ItemA->Postcode          = 'RM15DP';
$ItemA->CountryCode       = '';
$ItemA->OrgName           = 'Roman Empire';
$ItemA->DeptName          = '';
$ItemA->POBox             = '';
$ItemA->DeliveryPoint     = 'Over There';
$ItemA->ForeignAddress    = 0;
$ItemB->Years             = 3;
$ItemB->Months            = 8;

$Address[]  = array('CoreAddress' => $ItemA, 'TimeAtAddress' => $ItemB);

$Address is then absorbed in to the SOAPClient parameters further down the line (ie $Params->Address = $Address; )

It certainly generates XML as expected now (note that when I refer to generating XML, I’m refering to using __getLastRequest() when I’m tracing the request), the only downside being that it doesn’t appear to be closing the tags as in the above example (creates a close tag, rather than closing the open tag, if you know what I mean)