customUserNamePasswordValidatorType无法使用正确的类型

时间:2014-03-19 07:44:11

标签: c# wcf

我正在为消息级安全性配置服务,我使用UserName身份验证作为clientCredentialType。我已经检查了正确的类型但是在运行时出错了

Could not load file or assembly 'Service' or one of its dependencies.
The system cannot find the file specified.

这是web.config部分

<serviceCredentials>
        <serviceCertificate findValue="MyWebSite"
              storeLocation="LocalMachine"
              storeName="My"
              x509FindType="FindBySubjectName" />
        <userNameAuthentication userNamePasswordValidationMode="Custom"
         customUserNamePasswordValidatorType="Service.UserNamePassValidator,Service" />
      </serviceCredentials>

这是我提到UsernamePassValidator类型的服务模型的一部分

这是班级

namespace Service
{
public class UserNamePassValidator : System.IdentityModel.Selectors.UserNamePasswordValidator
{
    public override void Validate(string userName, string password)
    {
        if (!(userName == ConfigHelper.Get(ConfigHelper.CIMSBulkEmail, "ServiceUsername") 
            && userName == ConfigHelper.Get(ConfigHelper.CIMSBulkEmail, "ServicePassword")))
        {
            throw new FaultException("Invalid credentials");
        }
    }
}
}

我错过了什么吗?

2 个答案:

答案 0 :(得分:2)

将验证器类型放在配置中的位置,第二部分是包含该类的程序集的文件名。

Service.UserNamePassValidator, Service

这意味着您有一个名为Service.dll的DLL。但事实并非如此。

所以应该读取:

Service.UserNamePassValidator, CertraxIMSWebSite

答案 1 :(得分:0)

就我而言,我已经使用服务凭据给出了一个名称的行为,但是在web.config文件中保留了原始的默认行为,没有名称,也没有服务凭据要求。一旦我删除了默认行为(即使我已经按照服务合同的名称指定了行为),一切都按预期工作。我想任何具有空/无名称属性的行为都将适用于所有绑定?

相关问题