首页 > 解决方案 > 如何使用 Laravel 和 Soap 1.1 连接 Web 服务

问题描述

您好,我需要连接到 SOAP Web 服务才能从那里获取数据。SOAP 请求是:

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetDS4Response xmlns="http://tempuri.org/WAPSWS/WAPSWS">
      <GetDS4Result>
        <xsd:schema>schema</xsd:schema>xml</GetDS4Result>
    </GetDS4Response>
  </soap:Body>
</soap:Envelope>

我试试这个代码,但刀片上什么也没有

public function show()
    {
        $source = <<<SOURCE
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetDS4 xmlns="http://tempuri.org/WAPSWS/WAPSWS">
      <CommandString>select top 10 * from applpendingremark</CommandString>
    </GetDS4>
  </soap:Body>
</soap:Envelope>
SOURCE;


$xml = simplexml_load_string($source);
$xml->registerXPathNamespace('tempuri', 'http://moaqs.com/MOAQSWS/WAPSWS.asmx?op=GetDS4');
$elements = $xml->xpath('//soap:Envelope/soap:Body/tempuri:GetDS4/tempuri:GetDS4');
$result = json_encode($elements, true);
print_r($result);



        return view('aa.aa',compact('result'));
    }

提前致谢

标签: phplaravelweb-servicessoapsoap-client

解决方案


推荐阅读