tags:

views:

195

answers:

1

OK, I am getting myself a little confused here. I have a WCF service (service A) that calls another WCF service (service B). When I throw an exception on Service B e.g. throw new Exception("test") then service A does not get an exception, instead the IsFault is set to true on the response message e.g.

responseMessage = forwardingChannel.Process(message)
if (responseMessage.IsFault) {
    // Yes, there is a fault
}

I expected that I could put a try-catch around the Process method and receive the exception. Could someone explain to me what is going on here please?

Thanks

A: 

If Service A were a Java service, would you expect to get a .NET exception back from calling Service B?

By default, an unhandled exception in a WCF Service will be returned as fault. If the service is using SOAP, that will be returned as a SOAP Fault. In a normal WCF client, that will get translated into a FaultException.

John Saunders
OK thanks for the reply, but how do you get the SOAP Fault translated into a FaultException? Why doesn't that automatically happen on my WCF service but would do on a client?Thanks again
Jon Archway
If you use Add Service Reference in a client, then a SOAP Fault returned by the service _will_ be translated into a FaultException.
John Saunders
Yes, but in the case of an intermediary service you won't have a reference in the same way, so how do you then translate it? Thanks
Jon Archway
In exactly the same way! Look at the fault to try to figure out what went wrong.
John Saunders
I am doing thisMessageFault messageFault = MessageFault.CreateFault(response, int.MaxValue);throw new FaultException(messageFault);I assume this is the right way to do it then
Jon Archway