我一直在努力集成从PHP编写用.NET编写的WebService。我找到了这里描述的解决方案,但它对我没用:
PHP Parse SOAP XML response from SOAP Client
我将非常感谢您的支持。
编辑:感谢https://stackoverflow.com/users/1987598/mathias-m%C3%BCllerMathiasMü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"}';
}
?>
答案 0 :(得分:0)
似乎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()';-->
答案 1 :(得分:-1)
嗨我用soap webservice首次亮相,我有一个问题,我在数组&#34;注意:未定义的变量:第18行和第34行的C:\ wamp \ www \ soapwebservice2 \ productlist.php中的HTTP_RAW_POST_DATA;当我输入网址&#34; http://localhost/soapwebservice2/productlist.php&#34;