代码之家  ›  专栏  ›  技术社区  ›  gjb

php soapclient()函数返回单个XML字符串

  •  1
  • gjb  · 技术社区  · 15 年前

    我很难使用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。

    1 回复  |  直到 12 年前
        1
  •  1
  •   gjb    15 年前

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

    第三方SOAP服务器设计为返回XML格式的数据,嵌套在SOAP响应中。我现在正在用simpleXML分析XML响应。