antnee — 2010-04-06T06:37:50-04:00 — #1
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">
<BuildingName xsi:type="xsd:string">Building Name</BuildingName>
<Street1 xsi:type="xsd:string">Street Name</Street1>
<Locality1 xsi:type="xsd:string">Locality 1</Locality1>
<Postcode xsi:type="xsd:string">PO57 6DE</Postcode>
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:
So, how on earth do I pass these arrays to SOAPClient and have it process it as in the top example?
anthonysterling — 2010-04-06T06:59:50-04:00 — #2
You;re not actually trying to build the XML structure above are you?
antnee — 2010-04-06T07:02:56-04:00 — #3
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
anthonysterling — 2010-04-06T07:17:55-04:00 — #4
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!
antnee — 2010-04-06T07:19:42-04:00 — #5
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)