2010-03-16 111 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服務器。