【问题标题】:using a local WSDL to send to a remote URL使用本地 WSDL 发送到远程 URL
【发布时间】:2021-12-29 20:45:06
【问题描述】:

我正在尝试向本地打印机端点 - http://192.168.1.116/WebServices/PrinterService 发出 SOAP 请求。通常,要获取与您在 URL 末尾添加 ?wsdl 的端点相对应的 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 不总是发布到本地主机?

我在 WebPackage 目录中做了grep -r localhost . 并将所有这些实例替换为 192.168.1.116 并且仍然收到错误。

有什么想法吗?

【问题讨论】:

    标签: php web-services soap wsdl


    【解决方案1】:

    SoapClient 将使用 WSDL 中的地址进行调用。应该是这样的:

    <soap:address location="http://localhost...etc..."/>
    

    <soap12:address location="http://localhost...etc..."/>
    

    在您的 WSDL 文件中。 XML 前缀可能不同,但您应该有一个或两个地址。将此地址替换为您希望客户拨打电话的地址。

    要尝试的另一件事可能是为通话设置location

    $client = new SoapClient(dirname(__FILE__) . '/WebPackage/WSDPrinterService.wsdl', ['trace' => 1]);
    $client->__setLocation('http://192.168.1.116/WebServices/PrinterService');
    

    看看是否可行。

    【讨论】:

    • 更改 WSDL 中的位置对我没有用,但 $client-&gt;__setLocation(...) 可以。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2010-10-31
    • 2022-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-09
    • 1970-01-01
    相关资源
    最近更新 更多