Sunday, February 16, 2014

WCF channel is in the Faulted state Error - Fix

Today I ran into this problem when working with a WCF service.

The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.

The fix was mentioned here. http://stackoverflow.com/questions/2763592/the-communication-object-system-servicemodel-channels-servicechannel-cannot-be

You get this error because you let a .NET exception happen on your server side, and you didn't catch and handle it, and didn't convert it to a SOAP fault, either. 
Now since the server side "bombed" out, the WCF runtime has "faulted" the channel - e.g. the communication link between the client and the server is unusable - after all, it looks like your server just blew up, so you cannot communicate with it any more.

 The bottom line is,

When working with WCF, Always catch Exceptions and Wrap them in a FaultException<T>