n this article, we will see how we can use WCF fault contracts to handle exceptions. WCF gives you enough flexibility to handle exceptions and send required detail to clients. By default, WCF sends exception details to clients using SOAP FaultContract. The default FaultContract will allow you to set Message, Reason properties and throw it to clients.
Why we should use the FaultContract rather than using .Net exceptions?
Exceptions have limitations and security risks.
- .Net exception can be used by only CLR supported languages so losing great WCF feature of interoperability.
- Throwing exceptions can provide service implementation and private details to clients.
- Exceptions are tightly coupled between clients and service.
- Northwind WCF Services - WCF Services with implementation of Fault Contract.
- Client App - It is a client application consuming WCF services and using Fault contract response sent by WCF services.
Your project structure will be like this
For more details about implementation of FaultContract see https://geeksarray.com/blog/handling-wcf-service-exceptions-using-fault-contracts