Exception Handling in WCF

Posted: December 4, 2010 in WCF
Tags:


If you are new to wcf services,an obvious mistake that you would make while writing an exception handling code is by simply using a throw in catch block thinking that client can read it.This assumption is wrong and finally it would end up in the below error message.

“System.ServiceModel.FaultException: The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.”

In WCF, you should not throw standard .NET exceptions as your client could be designed in some other platform like Java which has no concept of .NET exceptions.Instead, you need to throw FaultExceptions which is the standard behavior for WCF

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s