简体   繁体   English

当wsdl将服务端口绑定定义为https和端口80时,PHP SOAP请求失败的解决方法?

[英]Workaround for PHP SOAP request failure when wsdl defines service port binding as https and port 80?

I am consuming a SOAP web service using php5's soap extension. 我正在使用php5的soap扩展来使用SOAP Web服务。 The service' wsdl was generated using Axis java2wsdl, and whatever options are used during generation result in the port binding url being listed as https ://xxx.xxx.xxx.xxx**:80** 服务'wsdl是使用Axis java2wsdl生成的,并且在生成期间使用的任何选项都会导致端口绑定URL列为https ://xxx.xxx.xxx.xxx**:80 **

If I download the wsdl to my server, remove the port 80 specification from the port binding location value, and reference the local file in my soapclient call it works fine. 如果我将wsdl下载到我的服务器,从端口绑定位置值中删除端口80规范,并在我的soapclient调用中引用本地文件它工作正常。

However, if I try to reference it remotely (or download it and reference it locally, as-is) the call fails with a soap fault. 但是,如果我尝试远程引用它(或下载并在本地引用它,原样),则调用将因soap故障而失败。

I have no input into the service side so I can't make them change their wsdl-generation process. 我没有输入服务端,所以我不能让他们改变他们的wsdl生成过程。 So, unless there's a way to make the soapclient ignorant of the port, I'm stuck with using a locally modified copy of someone else' wsdl (which I'd rather not do). 因此,除非有办法让soapclient对端口一无所知,否则我会坚持使用其他人'wsdl的本地修改副本(我宁愿不这样做)。

Any thoughts on how to make my soapclient ignore the port 80? 关于如何让我的soapclient忽略端口80的任何想法?

您可能希望尝试使用$ options数组覆盖主机名/端口,该数组可以作为SoapClient构造函数的第二个参数传递:

$client = new SoapClient("some.wsdl", array('proxy_host' => "https://example.org", 'proxy_port' => 443);

If you can't find a more elegant solution, you can always download the file, do the string replacements, then use that as the WSDL. 如果找不到更优雅的解决方案,可以随时下载文件,进行字符串替换,然后将其用作WSDL。

$cached_wsdl_file = './cached_wsdl.xml';
if (filemtime($cached_wsdl_file) > time() - 3600) {
    $wsdl = file_get_contents('http://server/service?wsdl');
    $wsdl = str_replace('server:80', 'server', $wsdl);
    file_put_contents($cached_wsdl_file, $wsdl);
}
$client = new SoapClient($cached_wsdl_file);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM