Showing posts with label Exception Handling. Show all posts
Showing posts with label Exception Handling. Show all posts

Thursday, December 17, 2009

Exception Handling Strategy by using WCF Services at Business layer for Enterprise .Net application

Today I would like to discuss a bit on the best practices for handling Exceptions in Enterprise applications where in WCF Service is used at the business layer

Ideally any standard Enterprise application will have 3 layers – Presentation, Business and Data Access.

Predominantly the WCF role will come in to play at Business layer (where in the real business rules are defined/ elicited).

So as a best practice it would be good if you follow these thumb rule at each layer to ensure the smoother operations or flow

Rule 1:

Identify & Define the Type of exception which you want to handle at the business layer

For ex : MyException

[DataContract]

Public class MyException

{

Describe/Collect the details which you want to handle.

}

Rule 2:

Decorate the method/operation with the identified exceptions – Define FaultContract’s for the Operations

For ex:

[ServiceContract]

Public interfact IMyService

{

[OperationContract]

[FaultContract(typeof(MyException))]

Void Get();

}

Rule 3:

Throw the FaultException at the Business layer.

For ex :






















Rule 4
At the configuration side – Enable Exception propagation












Rule 5:


At the Presentation layer catch the respective exception which you are throwing from the Business layer.









That’s it!!!

I hope this helps.

Regards,
-Vinayak