How to implement exception handling

Mar 20, 2009 at 12:36 PM
Hi

I need to trap a unique constraint exception on insert - I have tried working with the following link:

http://blogs.microsoft.co.il/blogs/bursteg/archive/2007/04/07/Shielding-WCF-Services-with-Exception-Handling-Application-Block-_2D00_-Part-1.aspx

using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF, making the entries in web.config and creating a ServiceFault contract class.


I am not sure where to put the try/catch in order to trap and throw the error as we have the repositories and NHibernate.

As well as following  the instructions in the article above, currently I have a try/catch around the repository insert method call to  

 

NHibernateSession.Save(myObject);

Then another around my Service Insert method call to:

myObjecttRepository.Insert(temp);

then in my UI form I catch:

 

catch

 

(FaultException<ServiceFault> exception)

 

 


and 

catch (Exception exception)

If I remove any of the try/catches I get a message that the exception was unhandled by user code.
And my UI doesn't trap the FaultException - only the Ex - reporting that

An error has occurred while consuming this service. Please contact your administrator for more information. Error ID: d48ffe03-9998-439f-8a6f-62ca9bcab2a8

 

 


Does anyone have an example working with Sculpture?

Many Thanks

 

Coordinator
Mar 23, 2009 at 12:27 PM
You can apply fault contracts in your WCF Services in many way.
The WCF Mold templates does not handle the fault contracts so you need to tweakthe templates to accomplish your task.
and consider the generated code as the code you write by your hand and implement your fault contracts since sculpture does not adhere specific structure in the WCF service.
I am really can not help you in using WCF Exception Handling Application Block Integration because I personally does not use it, but I emphasis that if you can implement it in a simple WCF Service then you can adopt the templates to use it.
Sure the exception handling for WCF Services will be available in Sculpture 2.
Thank You.
Negm.
Mar 26, 2009 at 6:36 AM
Well I discovered that the article had all I needed, but I just had to ensure that the web.config settings were complete.  I used the Enterprise Library Configuration Tool to get my settings right.

Thanks