Wednesday, May 10, 2017

Exception handling in WCF

WCF does not send exception detail in detail instead it throw a fault exception due to security reason. but some time we need the detailed exception for debugging purpose. We can achieve this using IncludeExceptionDetailInFault=True in config file.

<behavior name="includeExceptionDetails">
<serviceDebug includeExceptionDetailInFault="true" />

Also we can do it using ServiceBehavior attribute with IncludeExceptionDetails=true in class file.

What happens when an exception occurs in a WCF service?
OR What is SOAP fault?
How are WCF service exceptions reported to client application?
Ans Whenever any exception occured in WCF the exception is serialized in SOAP fault before
returned to the client and bydefault exception detail not included in the SOAP fault due to
security reaosn

Why use FaultExceptions?
This type of solution is very helpful in situations where the client and server are of different platforms. For examle, you might have client applications in Java or PHP. So, if there is any .NET specific exception in the service, we can't send the fault exception to the client directly, since client will not understand .NET based exceptions. They only need to know that an exception has occurred and if possible, a reason for it. So it becomes very important to use FaultExceptions normally only or use the strongly-typed fault exceptions.

What is Global Error Handling
Global Error Handling is writing the error handler code at centralize location instead for each function. We can do it using IErrorHandler interface.


No comments: