C# 在WCF中抛出FaultException

C# 在WCF中抛出FaultException,c#,wcf,exception-handling,C#,Wcf,Exception Handling,我有下面的类来实现我的服务 [ServiceBehavior(IncludeExceptionDetailInFaults = true)] public class CatalogueService : ICatalogueService 在一个方法中,我抛出了一个FaultException: public List<ProductType> GetProductType() { bool isThrow = true; if (isThrow)

我有下面的类来实现我的服务

[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class CatalogueService : ICatalogueService
在一个方法中,我抛出了一个
FaultException

public List<ProductType> GetProductType()
{
    bool isThrow = true; 
    if (isThrow)
        throw new FaultException(new FaultReason(new FaultReasonText("My fault Reason!")), new FaultCode("my fault code here"));
    else
    {
        .......
    }
}
但是问题不是抛出
FaultException
它的抛出
CommunicationException
。我做错了什么

编辑

也在
MessageBox.Show(fault.Reason.ToString())上我得到
NullReferenceException

对象引用未设置为对象的实例


我猜它甚至在代码执行之前就失败了……您能在服务中点击brakpoint吗?代码建议:
fault
可能是null-更改此
MessageBox.Show(fault==null?”:fault.Reason.ToString()
@Viru在
service.svn.cs
中,它确实会引发此异常,然后转到
Reference.cs
中,它认为
通信异常-未找到
void service_GetProductTypeCompleted(object sender, GetProductTypeCompletedEventArgs e)
{
    if (e.Error == null)
    {
        pType = e.Result.ToList();
        cboProductType.DataContext = pType;
    }
    else
    {
        FaultException fault = e.Error as FaultException;
        MessageBox.Show(fault.Reason.ToString());
    }
}