From Exceptions to Faults


A question that I often get asked during workshops on WCF is “Why does WCF use Faults instead of .NET Exceptions?”


Exceptions expose a set of limitations and possible security risks:


          They are platform/technology specific: .NET exceptions may have no meaning on other platforms


          Exceptions can cause tight-coupling between clients and service.


o   Clients need to understand exactly what exceptions can be thrown by each operation


          Flowing exceptions to clients may expose service implementation details


          Flowing exceptions to clients may expose private and personal information


          Exceptions and exception hierarchies are not easily represented using metadata


Therefore a map between exceptions on the service and their equivalent on the client is required. This is achieved using SOAP Faults.
It is worth mentioning that exceptions that reach WCF clients are represented as FaultException.


$0.02

Comments (5)

  1. I put together the following brief description of WCF Error Handling and some possible best practices

  2. I put together the following brief description of WCF Error Handling and some possible best practices

  3. Mickey says:

    I am using an ASMX service in my WCF service library. I am adding ASMX services as "Service References" in my WCF service library. I want to catch the soap exceptions thrown by the ASMX services. Can you please suggest me how can I do that?

  4. mary jain says:

    Thank you for sharing this knowledge… helpful for a beginner in WCF