tags:

views:

109

answers:

1

I noticed that if you do a throw new InvalidCastException for example, the channel state on the client side is faulted. But if you throw new FaultException, the channel state on the client side is opened.

By curiosity, what is the reason why one faults the channel and the other doesn't?

+12  A: 

The FaultException is a special case in WCF. It's meant to indicate that something happened on the service side that was an error, but at the same time, not fault the channel. This makes sense, given you can embed this information into the contract using the FaultContractAttribute to expose what can be expected from a contract.

Other exceptions are not really translatable in the WS world. Exceptions are a technology-specific abstraction, and each technology stack has a different representation of that abstraction (or in some cases, none at all).

That being said, when an exception that is not a fault exception is thrown on the server side, it is seen as catastrophic by the WCF runtime, and the channel must be faulted, as it is not known if you can proceed or not.

However, using FaultException, it implies you have some foresight into the conditions around why it was thrown and whether or not the underlying channel has been impacted or not.

casperOne
Thanks for the explanation. I was thinking of that, just wanted to make sure it was correct
pdiddy
@pdiddy: No problem, a lot of people don't realize that WCF isn't meant to map everything in .NET directly to the WS world, there are some very real things you have to know about it.
casperOne