公司业务需要,要求用 php 来调用 .Net 的 soap 服务,php5 默认的 soapclient 会给所有请求的数据加上 ns1 的 namespace,好像也没有找到可以配置的地方,所以会造成默认情况下的调用失败。最后通过重载系统 SoapClient 类的请求方法,解决了这个问题。
相关代码放在下面给需要的朋友参考:
1 2 3 4 5 6 7 8 9 | class DotNetSoapClient extends SoapClient { function __doRequest($request, $location, $action, $version) { $namespace = 'http://xxxx'; $request = preg_replace('/<ns1:(\w+)/', '<$1 xmlns="'.$namespace.'"', $request, 5); //最后面的数字可能要根据你的实际业务需要调整 $request = preg_replace('/<ns1:(\w+)/', '<$1', $request); $request = str_replace(array('/ns1:', 'xmlns:ns1="'.$namespace.'"'), array('/', ''), $request); return parent::__doRequest($request, $location, $action, $version); } } |
Comments 1
很好,很强大。
Posted 10 Aug 2009 at 8:55 am ¶Post a Comment