2010-07-02 42 views
3

我有一個調用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 = "",但目前爲止無濟於事。

回答

0

兩件事。確保您的WCF服務設置爲允許Windows憑據。確認您應該能夠將客戶端配置爲使用Windows憑據類型後。下面是一個示例(來自MSDN)。

WSHttpBinding myBinding = new WSHttpBinding(); 
myBinding.Security.Mode = SecurityMode.Message; 
myBinding.Security.Message.ClientCredentialType = MessageCredentialType.Windows; 
0

在你的app.config:

  • 地址:

    <system.net> 
        <defaultProxy useDefaultCredentials="true"></defaultProxy> 
    </system.net> 
    
  • 在你的元素綁定綁定/安全/運輸,設置proxyCredentialType = 「NTLM」

相關問題