php webservice 可能存在的坑

场景:

今天在生产机器上调用webservice失败 报 ...failed to load external entity...

 wget一下地址发现报500错误  把wsdl去掉再wget 发现就没有任何问题 ,一想估计是生成wsdl协议时出错了  于是找一下接口方看看,但没有发现任何问题。

用soapUI加载失败

WSDLException (at /SOAP-ENV:Envelope): faultCode=INVALID_WSDL: Expected element '{http://schemas.xmlsoap.org/wsdl/}definitions'. 

 

用浏览器打开接口地址发现一条信息(wget居然没给我显示出来)

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Server</faultcode>
<faultstring>WSDL generation is not supported yet</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

 


WSDL generation is not supported yet  看到这句话 我在想平时加上wsdl难道是虚假的没用的? 

单写一个php测试soap代码

$client = new SoapClient(null,array('location'=>'http://xxx.com/WebServerApi.php?wsdl','uri' =>'http://127.0.0.1/'));

发现去掉wsdl  和加上wsdl  完全没有任何影响,都能调取数据

再看看SoapClient方法解释

Description

public SoapClient::SoapClient ( mixed $wsdl [, array $options ] )
This constructor creates SoapClient objects in WSDL or non-WSDL mode.

Parameters

wsdl
URI of the WSDL file or NULL if working in non-WSDL mode.

 

 

第一个参数是填的null  表示不需定义wsdl,用这种方式是无法跨语言访问服务,因为我们访问拿不到wsdl,php之间调用还是可以,果然代码里面的地址写成?wsdl是装逼用的。

如果把null改为wsdl地址就会抛出异常

SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://xxx.com/WebServerApi.php?wsdl' : failed to load external entity 

ok 原因找到 结案!

posted @ 2016-07-15 14:52  wangxusummer  阅读(1915)  评论(0编辑  收藏  举报