3

如果我写错了标题,我很抱歉,我不熟悉 SOAP 响应和它的类型。但我想这是一个 WSDL 响应,至少我是从 WSDL 链接得到的......

我有以下网址 http://somedomain.com/j.svc?wsdl

在我使用 curl_multi 发出请求后,我得到了以下响应。响应缩短为两个结果,因此更易于阅读

响应如下:

<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>

有没有机会使用 PHP 解析结果?我进行了很多搜索,包括 StackOverflow 以及我设法找到的内容。

要解析上述响应,我可以使用以下代码:

$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);
   }

似乎上面的 PHP 代码部分是正确的。我得到了正确数量的“Journey”,但 $item 本身是空的。

有什么解决办法吗?请不要建议使用 SoapClient 来检索结果。我无法从 curl_multi 移动。我已经有了结果,我需要解析它。先感谢您

4

2 回答 2

0
$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';
      }
于 2018-07-05T02:34:20.310 回答
-1

首先尝试Parsing SOAP response然后尝试Google

于 2012-11-25T15:51:20.437 回答