我一直在努力集成从PHP读取用.NET编写的WebService。我找到了这里描述的解决方案,但它对我不起作用:
PHP Parse SOAP XML 响应 来自 SOAP 客户端
我将非常感谢您的支持。
编辑:由于 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"}';
}
?>
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()';-->