2011-03-02 13 views
2

是否有可能獲得用戶名和密碼,此代碼在客戶端提供:檢查的OperationContext用於Credentials.UserName

myChannelFactory.Credentials.UserName.UserName = "username"; 
myChannelFactory.Credentials.UserName.Password = "password"; 

在服務器端代碼?特別是在這種方法?:

public class MyAuthorizationManager : ServiceAuthorizationManager 
{ 
    protected override bool CheckAccessCore(OperationContext operationContext) 
    { 
    } 
} 
+0

你需要做什麼用戶名和密碼?執行自定義驗證? – 2011-03-02 16:46:32

+0

是的。在ServiceAuthorizationmanager中執行此操作的邏輯是,我想對正在Windows域中登錄的用戶執行附加檢查。 (我知道我可以 - 在簡單情況下 - 爲wcf認證創建自定義驗證器) – 2011-03-02 16:54:13

+0

您是否需要檢查用戶是否經過身份驗證並具有特定角色? – 2011-03-02 16:59:16

回答

1

寫的UserNamePasswordValidator派生的類,然後用你的WCF服務行爲定義

覆蓋「驗證(用戶名字符串,字符串密碼)」在您的課堂上使用它

然後web(app).config如下:

<behaviors> 
    <serviceBehaviors> 
    <behavior name="ClearServiceBehaviour"> 
     <serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true" /> 
     <serviceMetadata httpGetEnabled="true" /> 
     <serviceCredentials> 
     <userNameAuthentication userNamePasswordValidationMode="Custom" 
      customUserNamePasswordValidatorType="MyNamespace.MyCustomUserPassAuthenticator, MyAssembly" /> 
     </serviceCredentials> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 
+0

是的,我知道這個類,但問題是我還需要檢查WindowsCredentials(萬一用戶在域中註冊)。關鍵是我需要在CheckAccesscore方法中獲得用戶名和密碼,用戶名和密碼肯定在operationContext中,我只是不知道如何獲取它們。 – 2011-03-02 16:52:54