2009-02-26 180 views
3

我對SOAP非常陌生,我試圖在PHP中實現一個使用ASP.NET Web服務的快速測試客戶端。 Web服務依賴於包含授權參數的Soap Header。用PHP發送一個包含WSDL SOAP請求的Soap頭文件

當使用WSDL時,是否可以發送auth頭文件和soap請求?

我的代碼:

PHP

$service = new SoapClient("http://localhost:16840/CTI.ConfigStack.WS/ATeamService.asmx?WSDL"); 
$service->AddPendingUsers($users, 3); // Example 

web服務

[SoapHeader("AuthorisationHeader")] 
[WebMethod] 
public void AddPendingUsers(List<PendingUser> users, int templateUserId) 
{ 
    ateamService.AddPendingUsers(users, templateUserId, AuthorisationHeader.UserId); 
} 

將如何在auth頭在這種情況下通過?或者我需要做一個低槓桿__soapCall()傳遞頭部?另外,我是否在PHP中調用正確的soap調用?

回答

6

您應該能夠創建一個頭,然後將其添加到客戶端,以便發送所有後續請求。您可能需要更改名稱空間參數。

$service = new SoapClient("http://localhost:16840/CTI.ConfigStack.WS/ATeamService.asmx?WSDL"); 
//      Namespace    Header Name   value must-understand 
$header = new SoapHeader('http://tempuri.org/', 'AuthorisationHeader', $value, false); 
$service->__setSoapHeaders(array($header)); 

$service->AddPendingUsers($users, 3); // Example 

更多信息here

3
$client = new SoapClient(PassportWebService); 
$apiauth =array('userName'=>HeaderName,'password'=>HeaderPassport,'ip'=>$onlineip); 

$authvalues = new SoapVar($apiauth, SOAP_ENC_OBJECT,'ReqHeader',"SoapBaseNameSpace"); 
$header = new SoapHeader("SoapBaseNameSpace","ReqHeader", $authvalues, true); 
$client->__setSoapHeaders(array($header));