[ILUG] Calling web services with PHP

Niall O Broin niall at linux.ie
Wed Jul 29 10:26:33 IST 2009


I'm having fun and games trying to use web services with PHP. Looking at
http://web.services.sample/Services.asmx?op=Find  I see this in the  
sample request

<Find xmlns="http://web.services.sample/Services">
         <Number>string</Number>
         <startRows>int</startRows>
         <numRows>int</numRows>
</Find>

and the following code works to access this service:

$result = $client->Find(array('Number' => 
$number,'startRows'=>1,'numRows'=>1000));

having created a client with

$client = new SoapClient("http://web.services.sample/Services.asmx? 
WSDL",
                          array('features' =>  
SOAP_SINGLE_ELEMENT_ARRAYS | SOAP_USE_XSI_ARRAY_TYPE,
                                'soap_version'   => SOAP_1_2,
                                'compression' =>  
SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP));

However, from  http://web.services.sample/Services.asmx?op=Save  I see  
this in the sample request

<Save xmlns="http://web.services.sample/Services">
     <Details>xml</Details>
</Save>

I then create the Details XML as a SimpleXML object (which appears to  
be correctly populated, and
echo htmlentities($Details->asXML(), ENT_QUOTES);  looks just fine.)  
but the following code does
NOT work to access the service

$result = $client->Save(array('Details' => $Details->asXML()));

because what's sent to the server (from tcpdump) is

<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"  
xmlns:ns1="http://web.services.sample/Services">
<env:Body><ns1:Save><ns1:Details/></ns1:Save></env:Body>
</env:Envelope>

i.e. Details is an empty node which of course is a bit useless. So  
what the hell do I have to do to pass the XML as the content of the  
Details node?


Niall




More information about the ILUG mailing list