Dealing with exceptions in WCF services

19Oct10

Overview

Windows Communication Foundation Web services handle exceptions differently than regular .NET code. So in much the same that we re-throw CRM exceptions, we have to handle .NET exceptions at the top-level of our service methods in order to avoid the dreaded generic “NotFound” errors that we get when a WCF service fails for some reason.

For code that calls WCF services we can construct a FaultException to wrap the general exception that is thrown like this:

		try {
				
                            // perform the action that could throw an exception
			}
			catch( Exception e ) {
				throw new FaultException(
					new FaultReason( e.Message ),
					new FaultCode( e.GetType().ToString() )
				);
			}

However in Silverlight this doesn’t seem to work as expected. I still get a “Not Found” exception. Back to the drawing board.

Advertisements


No Responses Yet to “Dealing with exceptions in WCF services”

  1. Leave a Comment

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


%d bloggers like this: