我有一個調用WCF Web服務的WPF窗口客戶端。用戶在啓動應用程序之前已經登錄到Windows域,並且WCF服務使用Windows身份驗證。如何告訴WCF客戶端代理類使用Windows身份驗證和已登錄的域用戶的WindowsPrincipal作爲憑據?
我希望WPF客戶端在調用WCF服務時使用已經登錄的用戶的WindowsPrincipal。我不想創建一個帶有EXPLICIT用戶名&密碼的新NetworkCredential實例,只是因爲要求用戶登錄兩次(在Windows和應用程序中)是......非常漂亮的用戶不友好。
大多數我見過用這種方式來設置憑據,這是不是我想要
serviceClientProxy.ClientCredentials.Windows.ClientCredential
= new NetworkCredential("username", "password", "domain");
取而代之的是樣品,我想這樣做
serviceClientProxy.ClientCredentials.Windows.AllowedImpersonationLevel
= TokenImpersonationLevel.Identification;
serviceClientProxy.ClientCredentials.Windows.ClientCredential
= { /* network credential for already logged in user */ }
也就是說,我要的NetworkCredential對於已經存在的(和工作)
new WindowsPrincipal(WindowsIdentity.GetCurrent())
有沒有人知道如何做到這一點?我已經嘗試在app.config中設置security mode = ""
和傳輸clientCredentialType = ""
,但目前爲止無濟於事。