我有UserNamePasswordValidator
:
public class EmployeeValidator : UserNamePasswordValidator
{
public override void Validate(String userName, String password)
{
//...
throw new MessageSecurityException("Username and password cannot be empty.");
//...
}
}
在ViewModel
:
private void Login()
{
try
{
_cl.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
_cl.ClientCredentials.UserName.UserName = UserName;
_cl.ClientCredentials.UserName.Password = Password;
_cl.Login(UserName)
}
catch
{ /*...*/ }
}
问题是,我无法捕获异常。我做错了什么?
答案 0 :(得分:0)
启动小提琴手,我打赌代码是501(可能是我看了很久以来500次),然后搜索如何在wcf中重写错误代码。
如果它不是501,那么您的连接将不会中止,您可以正确处理错误(错误)