2009-05-19 51 views
0

我有一個簡單的Web服務,通​​過基於表單的身份驗證處理安全性。基於WCF表單的身份驗證通過Web應用程序 - 傳遞證書

WCFTestService.ServiceClient myService = new 
      WCFTestService.ServiceClient(); 
myService.ClientCredentials.UserName.UserName = "user"; 
myService.ClientCredentials.UserName.Password = "secret"; 
lblResult.Text = myService.GetData(1231); 
myService.Close(); 

我正在通過網絡應用程序訪問它。所以我想要做一次以上的事情,但是爲了安全/性能,不必再做一次。我想是這樣的下面,但因爲我使用FormsAuthentication這不會工作...

//Obtain the authenticated user's Identity and impersonate the original caller 
using (((WindowsIdentity)HttpContext.Current.User.Identity).Impersonate()) 
{ 
    WCFTestService.ServiceClient myService2 = new WCFTestService.ServiceClient(); 
    lblResult.Text = "From Logged On Credentials"+myService2.GetData(1231); 
    myService2.Close(); 
} 

回答

1

你試圖做的是建立你的客戶和你的服務之間的「安全對話」。這是一個只適用於wsHttpBinding的概念 - 所以如果你沒有使用特定的綁定,它將無法工作。

要建立安全會話,您需要在客戶端和服務器的配置文件中設置一些特定的配置屬性 - 您可以通過閱讀文檔(查找「establishSecurityContext」)或查看Michele Leroux Bustumante在MSDN上的優秀WCF screencast on security fundamentals

但真的:我不會建議通過一切手段使用安全會話。在正常情況下,使用每個通話服務是首選選項,每個服務通話重新進行身份驗證的開銷實際上可以忽略不計。

Marc