1

I have service configured for FaultException but on the client end I am not getting the exception caught in

catch (FaultException<MyServiceFault> fe)
{
} 

instead it is always caught in

catch (FaultException fx) 
{ 
}

I am using selfhost and channelfactory.

my Service:

[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");
    }
}

I also have the [DataContract] attribute on the MyServiceFault. I am wondering if I miss any configuration.

Juan M. Elosegui
  • 6,471
  • 5
  • 35
  • 48
user824910
  • 1,067
  • 6
  • 16
  • 38

1 Answers1

1

I've answered a similar question here: Proper way to throw exception over WCF

Try to declare your operation like this:

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

Hope it helps.

Community
  • 1
  • 1
Ricardo Pontual
  • 3,749
  • 3
  • 28
  • 43