2010-03-16 57 views
7

这里有许多关于PHP和SOAP的问题。但我没有找到对我的情况的答案。PHP和SOAP。更改信封

所以。我为它使用PHP SoapClient和WSDL。对象发送此:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.site.com"><SOAP-ENV:Body> 

但我需要这样的:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body> 

问题。我如何使用标准的PHP类SoapClient做到这一点?

谢谢。

+0

我认为这意味着你的WSDL不正确?你是否也创建了SOAP服务器部分? – Clutch 2010-03-16 18:25:22

+0

不,WSDL是正确的,因为其他库(用于C#的ActiveX控件)适用于它并发送真正的命名空间。 我无法更改SOAP服务器。我需要使用它来访问服务功能。 – Oleg 2010-03-17 10:09:54

+0

如果您认为这会导致与SOAP服务通信时出现问题,则这可能是不正确的假设。您的错误可能与您的消息中遗漏的属性有关,就像刚刚发生的那样。 – bytespider 2014-02-20 11:37:00

回答

5

我寻找答案的php.net

<?php 
class MSSoapClient extends SoapClient { 

    function __doRequest($request, $location, $action, $version) { 
     $namespace = "http://tempuri.com"; 

     $request = preg_replace('/<ns1:(\w+)/', '<$1 xmlns="'.$namespace.'"', $request, 1); 
     $request = preg_replace('/<ns1:(\w+)/', '<$1', $request); 
     $request = str_replace(array('/ns1:', 'xmlns:ns1="'.$namespace.'"'), array('/', ''), $request); 

     // parent call 
     return parent::__doRequest($request, $location, $action, $version); 
    } 
} 

$client = new MSSoapClient(...); 
?> 

此代码更改信封的请求。并需要ASP SOAP服务器。