Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从WCF测试客户端运行WCF服务时指定客户端凭据_C#_Wcf_Authentication - Fatal编程技术网

C# 从WCF测试客户端运行WCF服务时指定客户端凭据

C# 从WCF测试客户端运行WCF服务时指定客户端凭据,c#,wcf,authentication,C#,Wcf,Authentication,我有一个用于从WCF测试客户端运行的WCF服务。现在我已经在我的服务中添加了带有用户名和密码的自定义身份验证,我想知道如何传递用户名和密码?仍然可以通过WCF测试客户端指定客户端凭据吗 以下是我的自定义验证器和用户帐户类: public class CustomUserValidator : UserNamePasswordValidator { public override void Validate(string userName, string password) {

我有一个用于从WCF测试客户端运行的WCF服务。现在我已经在我的服务中添加了带有用户名和密码的自定义身份验证,我想知道如何传递用户名和密码?仍然可以通过WCF测试客户端指定客户端凭据吗

以下是我的自定义验证器和用户帐户类:

public class CustomUserValidator : UserNamePasswordValidator
{
    public override void Validate(string userName, string password)
    {
        if (null == userName || null == password)
        {
            throw new ArgumentNullException();
        }

        UserAccountModel uam = new UserAccountModel();

        if(uam.Login(userName, password))
            return;
        throw new SecurityTokenException("User invalid.");

    }
}



public class UserAccountModel
{

    private List<UserAccount> listUserAccounts = new List<UserAccount>();

    public UserAccountModel()
    {
        using (UserAccountContext ctx = new UserAccountContext())
        {
            listUserAccounts = ctx.UserAccounts.ToList();
        }
    }

    public bool Login(string _usrname, string _pwd)
    {
        return listUserAccounts.Count(lua => lua.Username.Equals(_usrname) && lua.Pwd.Equals(_pwd)) > 0;
    }
}
公共类CustomUserValidator:UserNamePasswordValidator
{
公共覆盖无效验证(字符串用户名、字符串密码)
{
如果(null==用户名| | null==密码)
{
抛出新ArgumentNullException();
}
UserAccountModel uam=新的UserAccountModel();
if(uam.Login(用户名、密码))
返回;
抛出新的SecurityTokenException(“用户无效”);
}
}
公共类UserAccountModel
{
私有列表listUserAccounts=新列表();
公共用户帐户模型()
{
使用(UserAccountContext ctx=new UserAccountContext())
{
listUserAccounts=ctx.UserAccounts.ToList();
}
}
公共bool登录(string\u usrname,string\u pwd)
{
返回listUserAccounts.Count(lua=>lua.Username.Equals(_-usrname)和&lua.Pwd.Equals(_-Pwd))>0;
}
}

您可以使用clientCredentials端点行为来指定客户端凭据,例如证书。您必须创建一个自定义扩展名。但是您是否考虑过暂时关闭身份验证?毕竟,测试客户端仅用于测试目的。

请向我们展示您的代码。我为什么要关闭身份验证?