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:
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!!!
Regards,
-Vinayak
1 comment:
Keep posting stuff like this i really like it
Post a Comment