2010-10-25 105 views
8

我一直在为WCF服务创建一个自定义的用户名/密码验证器,并且运行了配置项customUserNamePasswordValidatorType。我已经能够通过下面的例子使我的代码工作,但我只是不明白发生了什么。不幸的是,MSDN article没有提供太多细节。customUserNamePasswordValidatorType发生了什么?

这是Microsoft提供的样品:

<serviceCredentials> 
    <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="Microsoft.ServiceModel.Samples.CalculatorService.CustomUserNameValidator, service" /> 
</serviceCredentials> 

我试图了解这两个参数是customUserNamePasswordValidatorType:“Microsoft.ServiceModel.Samples.CalculatorService.CustomUserNameValidator”和“服务”。

有人可以帮我理解这些参数是什么意思吗?

谢谢!

回答

10

这第一个参数是该函数的自定义验证的完全合格的名称。第二个参数是组件的名称功能包含英寸

从如何使用自定义的验证器(略作修改,以适应你的例子)

namespace Microsoft.ServiceModel.Samples.CalculatorService 
{ 
    public class CustomUserNameValidator : UserNamePasswordValidator 
    { 
    // This method validates users. It allows in two users, 
    // test1 and test2 with passwords 1tset and 2tset respectively. 
    // This code is for illustration purposes only and 
    // MUST NOT be used in a production environment because it 
    // is NOT secure. 
    public override void Validate(string userName, string password) 
    { 
     if (null == userName || null == password) 
     { 
     throw new ArgumentNullException(); 
     } 

     if (!(userName == "test1" && password == "1tset") && !(userName == "test2" && password == "2tset")) 
     { 
     throw new FaultException("Unknown Username or Incorrect Password"); 
     } 
     } 
    } 
} 

a much better example采取以上将内得到遵守程序集名为service

+0

太棒了!谢谢! – Jacob 2010-10-25 21:13:43

6

第一部分是通过命名空间完全限定类名,第二个是组件的类是在。

+0

感谢您的帮助! – Jacob 2010-10-25 21:37:19

+0

直接准确,谢谢! – 2012-12-17 12:49:53