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

前提是你 提交于 2019-12-20 04:26:58

问题


I am consuming a SOAP web service using php5's soap extension. 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**

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.

However, if I try to reference it remotely (or download it and reference it locally, as-is) the call fails with a soap fault.

I have no input into the service side so I can't make them change their wsdl-generation process. 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).

Any thoughts on how to make my soapclient ignore the port 80?


回答1:


You might want to try overriding the hostname/port using the $options array that you can pass as the second argument to SoapClient's constructor:

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




回答2:


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.

$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);


来源:https://stackoverflow.com/questions/1439615/workaround-for-php-soap-request-failure-when-wsdl-defines-service-port-binding-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!