PHP SoapClient() function returning a single XML string

Posted by gjb on Stack Overflow See other posts from Stack Overflow or by gjb
Published on 2010-03-16T18:21:57Z Indexed on 2010/03/17 22:41 UTC
Read the original article Hit count: 515

Filed under:
|
|
|

I am having difficulty with the PHP SoapClient() function. The SOAP request is successful, but the response is returned as an object containing a single XML string with the key "any". For example:

<?php
$params = array('strUsername' => 'Test',
                'strPassword' => 'Test');

$client=new SoapClient('http://www.example.com/webservice.asmx?wsdl',
                       array('features' => SOAP_SINGLE_ELEMENT_ARRAYS));

$result = $client->strExampleCall($params);
print_r($result);
?>

This outputs the following:

stdClass Object
(
    [strExampleCallResult] => stdClass Object
    (
        [any] => <Response xmlns="" release="1.0.0" environment="Production" lang="en-GB"><ApplicationArea><Sender><SenderId>0</SenderId><ReferenceId>0</ReferenceId></Sender><Destination><DestinationId>1</DestinationId></Destination></ApplicationArea><DataArea><Result>1</Result></DataArea></Response>
    )
)

Subsequently, I cannot access properties of the object as I'd expect to:

echo $result->strExampleCallResult->Response->DataArea->Result;

Why isn't PHP parsing the SOAP response into properties of the returned object?

I am using PHP 5.3.0 and believe the SOAP server is running .NET.

Any suggestions will be much appreciated.

© Stack Overflow or respective owner

Related posts about php

Related posts about soap