1
我遇到了PHP SoapClient()函數的困難。 SOAP請求成功,但是響應作爲包含單個XML字符串的對象以「any」鍵返回。例如:返回單個XML字符串的PHP SoapClient()函數
<?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);
?>
此輸出以下:
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>
)
)
隨後,如我期望到我無法訪問該對象的屬性:
echo $result->strExampleCallResult->Response->DataArea->Result;
爲什麼不PHP將SOAP響應解析爲返回對象的屬性?
我使用PHP 5.3.0,並相信SOAP服務器正在運行.NET。