是否有更多 customUserNamePasswordValidatorType 实例?

Are there more customUserNamePasswordValidatorType instances?

是否只有一个 customUserNamePasswordValidatorType 实例,或者每个 "application" 是否可能有多个实例?
如果有更多的实例,是否在某处写了逻辑,当它们被创建时(例如每次登录一个实例,每小时或其他)?

据我所知,只有一个 customUserNamePasswordValidatorType 实例。无论 WCF 应用程序以何种方式运行,单实例还是多实例,每个使用该服务的人总是有一个验证逻辑实例。

using (WebServiceHost sh = new WebServiceHost(typeof(MyService), uri))
{
    sh.AddServiceEndpoint(typeof(IService), binding, "");
    ServiceMetadataBehavior smb;
    smb = sh.Description.Behaviors.Find<ServiceMetadataBehavior>();
    if (smb == null)
    {
        smb = new ServiceMetadataBehavior()
        {
            HttpGetEnabled = true
        };
        sh.Description.Behaviors.Add(smb);
    }
    sh.Credentials.UserNameAuthentication.UserNamePasswordValidationMode = System.ServiceModel.Security.UserNamePasswordValidationMode.Custom;
    sh.Credentials.UserNameAuthentication.CustomUserNamePasswordValidator = new CustUserNamePasswordVal();
    Binding mexbinding = MetadataExchangeBindings.CreateMexHttpBinding();
    sh.AddServiceEndpoint(typeof(IMetadataExchange), mexbinding, "mex");
    sh.Opened += delegate
    {
        Console.WriteLine("Service is ready");
    };
    sh.Closed += delegate
    {
        Console.WriteLine("Service is clsoed");
    };
    sh.Open();
    Console.ReadLine();
    //pause
    sh.Close();
    Console.ReadLine();
}

和验证class,UserNamePasswordValidator。

    internal class CustUserNamePasswordVal : UserNamePasswordValidator
    {
        public override void Validate(string userName, string password)
        {
            if (userName != "jack" || password != "123456")
            {
                throw new FaultException("Username/Password is not correct");
            }
        }
}

官方 link.
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-use-a-custom-user-name-and-password-validator
https://docs.microsoft.com/en-us/dotnet/framework/wcf/samples/user-name-password-validator
也许我不完全明白你的意思,如果有什么我能帮忙的,请随时告诉我。