2011-12-21 74 views
4

我想使用PHP SoapClient擴展與外部SOAP服務器進行通信。PHP SoapClient:操作不匹配

這是我的代碼:

$this->_client = new SoapClient(SOAP_TAGGING_URL, array(
    'trace' => 1, 
    'soap_version' => SOAP_1_2, 
    'cache_wsdl' => WSDL_CACHE_NONE, 
    'exceptions' => true, 
    'uri' => SOAP_URI, 
)); 
try { 
    $actionHdr = array(); 
    $actionHdr[] = new SoapHeader(SOAP_TAGGING_URL, 'Action', 'GetMessagesByTagsByGroup'); 
    $this->_client->__setSoapHeaders($actionHdr); 
    $info = $this->_client->GetMessagesByTagsByGroup( 
     new SoapParam($this->params['mPID'], 'ParentMessageID'), 
     new SoapParam($gid, 'GroupId'), 
     new SoapParam(REQUEST_TOKEN, 'RequestToken'), 
     new SoapParam(ACCESS_TOKEN, 'AccessToken'), 
     new SoapParam(ACCESS_TOKEN_SECRET, 'AccessTokenSecret') 
    ); 
} catch (SoapFault $fault) { 
    print("\n<br/>SOAP server returned the following ERROR: ".$fault->faultcode."-".$fault->faultstring); 
} 

echo "\n<br/>SOAP request: ". htmlentities($this->_client->__getLastRequest()); 
echo "\n<br/>SOAP response: ". htmlentities($this->_client->__getLastResponse()); 

這是我得到(格式化添加的)響應:

SOAP server returned the following ERROR: s:Sender-The SOAP action specified on the message, '', does not match the HTTP SOAP Action,  'http://tempuri.org/ITagging/GetMessagesByTagsByGroup'. 
SOAP request: 
<?xml version="1.0" encoding="UTF-8"?> 
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://tempuri.org/" xmlns:ns2="https://mywebserver.com/myWSDL.svc/ws?wsdl"> 
    <env:Header> 
     <ns2:Action>GetMessagesByTagsByGroup</ns2:Action> 
    </env:Header> 
    <env:Body> 
     <ns1:GetMessagesByTagsByGroup/> 
      <GroupId>2178</GroupId> 
      <RequestToken>odwedwo09i0jACqbbjsw6KnlCA=</RequestToken>   
      <AccessToken>OlVbHurPJrNrEFR54Y0hV9kI/TZs=</AccessToken> 
      <AccessTokenSecret>js1kerfe453FLuaXpL 892DY o=</AccessTokenSecret> 
    </env:Body> 
</env:Envelope> 
SOAP response: 
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing"> 
<s:Header> 
    <a:Action s:mustUnderstand="1">http://www.w3.org/2005/08/addressing/fault</a:Action>  
</s:Header> 
    <s:Body> 
     <s:Fault> 
      <s:Code> 
       <s:Value>s:Sender</s:Value> 
       <s:Subcode> 
        <s:Value>a:ActionMismatch</s:Value> 
       </s:Subcode> 
      </s:Code> 
      <s:Reason> 
       <s:Text xml:lang="en-US">The SOAP action specified on the message, '', does not match the HTTP SOAP Action, 'http://tempuri.org/ITagging/GetMessagesByTagsByGroup'. </s:Text> 
      </s:Reason> 
      <s:Detail> 
       <a:ProblemHeaderQName>a:Action</a:ProblemHeaderQName> 
      </s:Detail> 
     </s:Fault> 
    </s:Body> 
</s:Envelope> 

我想我加入了「操作」參數在頭,但顯然這不是放置它的地方。還是我在做其他事情?

不幸的是,我無法嘗試NuSoap,因爲我無法控制服務器。

謝謝

+0

你試過使用zend肥皂? – 2011-12-21 23:56:38

回答

1

你把它當作SOAPHEADER,但實際上它是HTTP標頭。

我發現這樣做的方式是:http://lt.php.net/manual/en/soapclient.dorequest.php通過設置$ action參數。

您可能需要擴展SoapClient類以使用較少的代碼行來完成此操作。

+1

SoapHeader和HTTP頭有什麼區別?我在執行__doRequest之前擴展了SoapClient類以轉儲操作名稱,並且操作已經在那裏設置。 我嘗試了很多方法和選項,但我仍然得到相同的錯誤。 – 2012-01-11 19:17:19

2

它意味着意味着你不僅必須指定HTTP標頭的SOAPAction:「http://www.bla.com:MyAction」

,但你還需要指定在SOAP信封頭: 檢查這些鏈接的一些ref: SOAP ACTION

+1

我不確定WSClient類與SoapClient類不同。我在標題中設置了該操作,但似乎被忽略。 – 2012-01-11 19:21:17