我正在嘗試向本地列印機端點發出 SOAP 請求 - http://192.168.1.116/WebServices/PrinterService。通常要獲取與您附加?wsdl到 URL 末尾的端點相對應的 WSDL,但在這種情況下不起作用。
幸運的是,可以從https://docs.microsoft.com/en-us/windows-hardware/drivers/print/ws-print-v1-1下載 WSDL 。因此,我可以從本地檔案系統中讀取它:
$client = new SoapClient(dirname(__FILE__) . '/WebPackage/WSDPrinterService.wsdl', ['trace' => 1]);
$client->SendDocument();
問題是這段代碼總是出現以下錯誤:
[29-Dec-2021 14:39:11 America/Chicago] PHP Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host in /home/neubert/test.php:9
Stack trace:
#0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'http://localhos...', 'http://schemas....', 1, 0)
#1 /home/neubert/test.php(9): SoapClient->__call('SendDocument', Array)
#2 {main}
thrown in /home/neubert/test.php on line 9
__doRequest( $location)的第二個引數是“http://localhos...”。這很可能是 localhost 被截斷了。
我的問題是……我如何才能使本地檔案系統上的 WSDL 不總是發布到本地主機?
我grep -r localhost .在 WebPackage 目錄中做了,用 192.168.1.116 替換了所有這些實體,但仍然出現錯誤。
有任何想法嗎?
uj5u.com熱心網友回復:
SoapClient 將使用 WSDL 中的地址進行呼叫。應該有類似的東西:
<soap:address location="http://localhost...etc..."/>
或者
<soap12:address location="http://localhost...etc..."/>
在您的 WSDL 檔案中。XML 前綴可能不同,但您應該在那里有一個或兩個地址。將此地址替換為您希望客戶撥打電話的地址。
另一件要嘗試的事情可能是為呼叫設定一個位置:
$client = new SoapClient(dirname(__FILE__) . '/WebPackage/WSDPrinterService.wsdl', ['trace' => 1]);
$client->__setLocation('http://192.168.1.116/WebServices/PrinterService');
看看這是否有效。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/397905.html
