3

我在使用 PHP SoapClient() 函数时遇到了困难。SOAP 请求成功,但响应作为一个对象返回,该对象包含一个带有键“any”的 XML 字符串。例如:

<?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。

4

1 回答 1

2

我现在已经解决了这个问题。

第三方 SOAP 服务器旨在以 XML 格式返回数据,嵌套在 SOAP 响应中。我现在正在使用 SimpleXML 解析 XML 响应。

于 2010-03-17T22:36:59.893 回答