【问题标题】:SoapClient returns one long stringSoapClient 返回一个长字符串
【发布时间】:2014-12-21 08:54:57
【问题描述】:

这是 WSDL 格式:

http://www.petango.com/webservices/wsadoption.asmx?WSDL

我正在使用开发人员提供的测试服务器,它表示它将返回以下 XML 格式的 SOAP 响应:

<ArrayOfXmlNode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.petango.com/">

<!-- Animal 1 // -->
<XmlNode>
<adoptableSearch xmlns="">
<ID>10270740</ID>
<Name>Peyton</Name>
<Species>Dog</Species>
<Sex>Male</Sex>
</adoptableSearch>
</XmlNode>

...

<!-- Animal n - 1 // -->
<XmlNode>
<adoptableSearch xmlns="">
<ID>4252534</ID>
<Name>Chilli</Name>
<Species>Dog</Species>
<Sex>Male</Sex>
</adoptableSearch>
</XmlNode>

</ArrayOfXmlNode>

我设置了 SOAP 调用:

$wsdl = 'http://www.petango.com/webservices/wsadoption.asmx?WSDL';
$client = new SoapClient($wsdl);

$params = array(
  'authkey' => 'myauthkey',
  'speciesID' => '',  
  'sex' => '',
  'ageGroup' => '',
  'location' => '',
  'site' => '',
  'onHold' => '',
  'orderBy' => '',
  'primaryBreed' => '',
  'secondaryBreed' => '',
  'specialNeeds' => '',
  'noDogs' => '',
  'noCats' => '',  
  'noKids' => '',
  'stageID' => ''
);

$result = $client->AdoptableSearch($params);

然后我打印出来:

echo print_r($result, true);

当我查看源代码时,我得到:

stdClass Object
(
  [AdoptableSearchResult] => stdClass Object
    (
      [XmlNode] => Array
        (
          [0] => stdClass Object
            (
              [any] => <adoptableSearch xmlns=""><ID>10270740</ID><Name>Peyton</Name><Species>Dog</Species><Sex>Male</Sex></adoptableSearch>
            )
          [1] => stdClass Object
        (
          [any] => <adoptableSearch xmlns=""><ID>10270740</ID><Name>Peyton</Name><Species>Dog</Species><Sex>Male</Sex></adoptableSearch>
        )
...

如您所见,一切都按预期返回,直到我们得到动物的实际细节。此时,结果是any 属性下的一个长XML 字符串。 any 属性是从哪里来的,为什么动物的详细信息没有像 xml 节点的结果那样分解成单独的属性或键?

【问题讨论】:

    标签: php web-services soap wsdl soap-client


    【解决方案1】:

    它是any,因为在adaptableSearch 的WSDL 文件响应中包含任何类型。

    <s:element minOccurs="0" maxOccurs="unbounded" name="XmlNode" nillable="true">
    <s:complexType mixed="true">
    <s:sequence>
    <s:any/>
    </s:sequence>
    </s:complexType>
    

    您可以使用此php方法将字符串xml转换为数组对象。

    simplexml_load_string [http://php.net/manual/en/function.simplexml-load-string.php]

    【讨论】:

    • 所以我必须手动执行,而且由于WSDL格式,没有办法自动获取字段分区?
    • 是的,我相信如此。有一些用于 php web 服务的框架wso2.com/products/web-services-framework/php 他们可能会这样做,但我没有尝试过 类型。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-06
    • 2019-12-06
    • 1970-01-01
    相关资源
    最近更新 更多