[英]PHP SOAP client with authentication required in function call
我對使用SOAP完全陌生,並且希望創建一些客戶端軟件來連接到現有服務,該服務不為PHP提供資源/演示。 我想確定我的代碼是否做錯了,或者這可能是系統問題(我已經在Windows Server 2008 R2環境中創建了Apache2.4 / PHP7.2.7)。
我已經花了幾個小時來測試事物,並在這里遍歷其他許多SOAP / PHP主題,而我要編寫自己的線程的區別是,在SoapClient調用中需要身份驗證,而實際上是$ client-> __ soapCall(function,params)調用。
首先,這就是我在PHP中所擁有的。
$customerArray = array( $cust1 , $cust2, $cust3 );
$credentials = array(
'login' => $login,
'password' => $password,
);
try{
$client = new SoapClient($soaplink);//, $credentials);
} catch (Exception $e) {
echo "<h2>Exception Error in SoapClient</h2>";
echo $e->getMessage();
}
var_dump($client->__getFunctions());
try{
$response = $client->__soapCall("getCustomers", array($customerArray, $credentials));
}catch (Exception $e) {
echo "<h2>Exception Error in soapCall</h2>";
echo $e->getMessage();
}
var_dump($response());
第一個try塊完成(帶有或不帶有憑據數組)。 嘗試調用該函數時,第二個try塊返回異常“看起來我們沒有XML文檔”。
SOAP服務提供了演示XML文件,用於此功能的文件如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns1:getCustomers
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:ns1="http://ws.praxedo.com/2008_07_01/customermodel/service"
>
<in0
soapenc:arrayType="soapenc:string[3]"
xsi:type="soapenc:Array" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
>
<in0 xsi:type="soapenc:string">CUSTOMER001</in0>
<in0 xsi:type="soapenc:string">CUSTOMER002</in0>
<in0 xsi:type="soapenc:string">CUSTOMER003</in0>
</in0>
<in1
xsi:type="soapenc:string"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
>
login|password
</in1>
</ns1:getCustomers>
</soapenv:Body>
</soapenv:Envelope>
還提供了WSDL文件,可能是我需要從中加載文件,但在進行演示后未提供任何結果。 我可以在此處包括一些WSDL,但我相信XML提供了所有相關細節?
因此,誰能在我的PHP中看到我在做錯什么,還是應該在做我正在做的事情,而我需要研究客戶端Apache / SOAP服務器端?
我強烈建議您使用WSDL to PHP生成器,因為它將允許您毫無疑問地構造請求(至少取決於您的PHP知識水平)。
嘗試PackageGenerator項目。 您必須先安裝它,然后生成PHP SDK。 生成的SDK使用composer,並包含發送任何請求所需的所有類和方法。 看一下自動生成的tutorial.php文件,這是一個很好的起點。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.