我使用 netTcpBinding 和安全模式="Message" 和 clientCredentialType="UserName" 编写了简单的 WCF 服务。当我传递有效的用户名和密码时,一切正常,会话以我想要的方式建立。但是,当凭据错误时,尽管我无法在 try catch 块中的客户端应用程序中捕获它,但会引发异常。有没有人有同样的问题?这是我的自定义验证器...
public class UserValidator : UserNamePasswordValidator
{
static int counter = 0;
public override void Validate(string userName, string password)
{
++counter;
Console.WriteLine(counter.ToString() + " " + DateTime.Now.ToShortTimeString());
if (userName != "test" || password != "test")
throw new FaultException("Bad username or password");
//throw new SecurityTokenException();
}
}