【问题标题】:Support PHP SOAP WebService支持 PHP SOAP WebService
【发布时间】:2015-01-15 22:04:01
【问题描述】:

我一直致力于从 PHP 集成读取用 .NET 编写的 WebService。我找到了此处描述的解决方案,但它对我不起作用:

PHP Parse SOAP XML response from SOAP Client

我将非常感谢您的支持。

编辑:感谢https://stackoverflow.com/users/1987598/mathias-m%C3%BCller Mathias Müller,此代码已经更正

我在下面编写的代码供您使用:

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$wsdl = 'http://www.wsplaces.com/Xofigo/wsAppXofigo.asmx?WSDL';
$trace = true;
$exceptions = false;

$data = array(
    'IdEdo' => '9'
);

$client = new SoapClient($wsdl, array('trace' => $trace, 'exceptions' => $exceptions));
$response = $client->__soapCall("Get_PlacesByEdo", array($data));

echo"<pre>";
print_r($client);
echo"</pre>";
echo"<pre>";
print_r($client->__last_response);
echo"</pre>";

$lastResponse='<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><Get_PlacesByEdoResponse xmlns="http://www.tempuri.org/"><Get_PlacesByEdoResult><IdEdo/></Get_PlacesByEdoResult></Get_PlacesByEdoResponse></soap:Body></soap:Envelope>'; 

 $xml = new SimpleXMLElement($lastResponse);
 $xml->registerXPathNamespace('xsi', 'http://www.w3.org/2001/XMLSchema-instance');
 $xml->registerXPathNamespace('xsd', 'http://www.w3.org/2001/XMLSchema');
 $xml->registerXPathNamespace('soap', 'http://schemas.xmlsoap.org/soap/envelope/');
 $xml->registerXPathNamespace('xml', 'http://www.w3.org/XML/1998/namespace');
 $xml->registerXPathNamespace('a', 'http://www.tempuri.org/');

 $xpath ='/soap:Envelope/soap:Body/a:Get_PlacesByEdoResponse/a:Get_PlacesByEdoResult/a:IdEdo/text()';

 $result = $xml->xpath($xpath);

 if ($result != FALSE && count($result) > 0) {
      echo '{"reference": "' . $result[0] . '", "success":"true"}';
 } else {
      echo '{"error": "si", "success":"false"}';
 }


 ?>

【问题讨论】:

  • 你写的有什么问题。你遇到了什么错误?由于上面的代码,发生了什么意外行为>

标签: php soap xpath


【解决方案1】:

XML 输入似乎不包含元素 a:Get_PlacesByEdo,因为输入 XML(以更易读的格式)看起来像

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Body>
      <Get_PlacesByEdoResponse xmlns="http://www.tempuri.org/">
         <Get_PlacesByEdoResult>
            <IdEdo/>
         </Get_PlacesByEdoResult>
      </Get_PlacesByEdoResponse>
   </soap:Body>
</soap:Envelope>

也许您试图找到 IdEdo 元素?

$xpath = '/soap:Envelope/soap:Body/a:Get_PlacesByEdoResponse/a:Get_PlacesByEdoResult/a:IdEdo/text()';-->

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-23
    • 2016-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-05
    • 1970-01-01
    相关资源
    最近更新 更多