[英]Parsing response from the WSDL using PHP
I'm very sorry if I made a wrong title, I'm not familiar with SOAP response and types of it.如果我写错了标题,我很抱歉,我不熟悉 SOAP 响应及其类型。 But I guess it's a WSDL response, at least I got it from WSDL link...但我想这是一个 WSDL 响应,至少我是从 WSDL 链接中得到的...
I have a following url http://somedomain.com/j.svc?wsdl我有以下网址http://somedomain.com/j.svc?wsdl
And after I made a request using curl_multi I got the following response.在我使用 curl_multi 提出请求后,我得到了以下响应。 The response was shortened to two results so it would be easier to read响应已缩短为两个结果,因此更易于阅读
The response is as following:响应如下:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<GetJourneyListResponse xmlns="http://tempuri.org/">
<GetJourneyListResult xmlns:a="http://schemas.datacontract.org/2004/07/DreamFlightWCF" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:Journey>
<a:FromAirport>LHR</a:FromAirport>
<a:TotalPrice>146</a:TotalPrice>
</a:Journey>
<a:Journey>
<a:FromAirport>LHR</a:FromAirport>
<a:TotalPrice>155</a:TotalPrice>
</a:Journey>
</GetJourneyListResult>
</GetJourneyListResponse>
</s:Body>
</s:Envelope>
Is there any chance to parse the result using PHP?有没有机会使用PHP解析结果? I made lots of searches including StackOverflow and here what I managed to find.我进行了大量搜索,包括 StackOverflow 和我设法找到的内容。
To parse the above response I can use following code:要解析上述响应,我可以使用以下代码:
$xml = simplexml_load_string($result);
$xml->registerXPathNamespace('flight','http://schemas.datacontract.org/2004/07/DreamFlightWCF');
foreach ($xml->xpath('//flight:Journey') as $item){
print_r($item);
}
It seems that the above PHP code piece is correct by partially.似乎上面的 PHP 代码部分是正确的。 I get the correct amount of "Journey"s but the $item by its own is empty.我得到了正确数量的“旅程”,但它自己的 $item 是空的。
Any solutions?任何解决方案? Please don't advise to use SoapClient to retrieve the result.请不要建议使用 SoapClient 来检索结果。 I can't move from curl_multi.我无法从 curl_multi 移动。 I already have the result and I need to parse it.我已经有了结果,我需要解析它。 Thank you in advance先感谢您
$soap_request = "<?xml version=\"1.0\"?>\n";
$soap_request .= "<soap:Envelope xmlns:soap=\"http://www.w3.org/2001/12/soap-envelope\" soap:encodingStyle=\"http://www.w3.org/2001/12/soap-encoding\">\n";
$soap_request .= " <soap:Body xmlns:m=\"http://www.example.org/stock\">\n";
$soap_request .= " <m:GetStockPrice>\n";
$soap_request .= " <m:StockName>IBM</m:StockName>\n";
$soap_request .= " </m:GetStockPrice>\n";
$soap_request .= " </soap:Body>\n";
$soap_request .= "</soap:Envelope>";
$header = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: \"run\"",
"Content-length: ".strlen($soap_request),
);
$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL, "http://ecc6unitst.kaisa.com:8000/sap/bc/srt/wsdl/bndg_386D2B5BD851F337E1000000AC1264E4/wsdl11/allinone/standard/document?sap-client=400" );
curl_setopt($soap_do, CURLOPT_USERPWD, "EBALOBORRP:welcome1");
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_TIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($soap_do, CURLOPT_POST, true );
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $soap_request);
curl_setopt($soap_do, CURLOPT_HTTPHEADER, $header);
$str = curl_exec($soap_do);
if(curl_exec($soap_do) === false) {
$err = 'Curl error: ' . curl_error($soap_do);
curl_close($soap_do);
print $err;
} else {
curl_close($soap_do);
var_dump($str);
print 'Operation completed without any errors';
}
首先尝试解析 SOAP 响应,然后尝试Google 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.