WCF故障异常<;T>;不是在客户端捕获,而是作为服务错误捕获

WCF故障异常<;T>;不是在客户端捕获,而是作为服务错误捕获,wcf,exception,faultexception,Wcf,Exception,Faultexception,我已经为FaultException配置了服务,但是在客户端我没有捕获到异常 catch (FaultException<MyServiceFault> fe) { } 我正在使用selfhost和channelfactory 我的服务: [FaultContract(typeof(MyServiceFault))] public string HelloWorld() { int a=5; try { var b = a/0; }

我已经为FaultException配置了服务,但是在客户端我没有捕获到异常

catch (FaultException<MyServiceFault> fe)
{
} 
我正在使用selfhost和channelfactory

我的服务:

[FaultContract(typeof(MyServiceFault))]
public string HelloWorld()
{
    int a=5;
    try
    {
        var b = a/0;
    }
    catch(Exception e)
    {
        throw new FaultException<MyServiceFault>(new MyServiceFault(){Message ="Divide by zero"}, "Divide by Zero");
    }
}
[FaultContract(typeof(MyServiceFault))]
公共字符串HelloWorld()
{
INTA=5;
尝试
{
var b=a/0;
}
捕获(例外e)
{
抛出新的FaultException(newmyServiceFault(){Message=“除以零”},“除以零”);
}
}
我还有
myservicecfault
上的
[DataContract]
属性。
我想知道是否遗漏了任何配置。

我在这里回答了一个类似的问题:

请尝试按以下方式声明您的操作:

[FaultContractAttribute(
        typeof(MyServiceFault),
        Action = "", 
        Name = "MyServiceFault", 
        Namespace = "YourNamespace")]
public string HelloWorld()

希望有帮助。

我觉得这一切都是正确的;您可以包括您获得的faultexception的详细信息吗?
[FaultContractAttribute(
        typeof(MyServiceFault),
        Action = "", 
        Name = "MyServiceFault", 
        Namespace = "YourNamespace")]
public string HelloWorld()