【发布时间】:2016-07-23 04:39:02
【问题描述】:
我有一个以前从 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;
}
}
【问题讨论】:
-
请向我们展示您的代码。
标签: c# wcf authentication