支持 PHP SOAP 网络服务

Support PHP SOAP WebService

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

PHP Parse SOAP XML response from SOAP Client

非常感谢您的支持。

编辑:感谢 https://whosebug.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"}';
 }


 ?>

似乎 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()';-->