C# 如何在WCF服务器中获得抛出的Exception

C# 如何在WCF服务器中获得抛出的Exception,c#,wcf,C#,Wcf,我正在开发一个WCF服务器,它使用wsHttpBinding和SecurityMode作为传输,使用CertificateValidation模式作为自定义,下面是我的自定义CertificateValidation类: public class CustomValidation : X509CertificateValidator { public override void Validate(X509Certificate2 certificate) { va

我正在开发一个WCF服务器,它使用
wsHttpBinding
SecurityMode作为传输
,使用
CertificateValidation模式作为自定义
,下面是我的自定义
CertificateValidation
类:

public class CustomValidation : X509CertificateValidator
{
    public override void Validate(X509Certificate2 certificate)
    {
        var store = new X509Store(StoreName.TrustedPeople, StoreLocation.LocalMachine);
        store.Open(OpenFlags.ReadOnly);

        if (store.Certificates.Contains(certificate))
        {
            store.Close();
            return;
        }
        else
        {
           store.Close();
           throw new Exception("TEST TEST");
       }
    }
}
我的客户端应用程序:

try
{
   var client = new HelloWorld.HelloWorldClient();

   ServicePointManager.ServerCertificateValidationCallback = (sender, cert, chain, error) => true;

   client.ClientCredentials.ClientCertificate.SetCertificate(
              StoreLocation.LocalMachine,
              StoreName.My,
              X509FindType.FindBySubjectName,
              "server.com");

   Console.WriteLine("IP: " + client.GetIp());
   Console.WriteLine("Certificate: " + client.GetCertificate());
}
catch (Exception ex)
{
   Console.WriteLine(ex.Message);
}
问题是,如果
Validate
方法失败,它会抛出一个异常,但在客户机中,我会收到另一个异常,表明

客户端身份验证方案“匿名”禁止HTTP请求

如何在客户端中获取“测试”消息


谢谢

听起来你需要将验证代码包装在里面,正在尝试{}cathc{}看起来这可能已经得到了回答[这里][1]。[1]: