Skip to content

Latest commit

 

History

History
25 lines (15 loc) · 1.5 KB

File metadata and controls

25 lines (15 loc) · 1.5 KB

Handling wcf service exceptions using fault contracts and data contracts

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.

  1. .Net exception can be used by only CLR supported languages so losing great WCF feature of interoperability.
  2. Throwing exceptions can provide service implementation and private details to clients.
  3. Exceptions are tightly coupled between clients and service.

Projects

  1. Northwind WCF Services - WCF Services with implementation of Fault Contract.
  2. 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

Add WCF Service reference

For more details about implementation of FaultContract see https://geeksarray.com/blog/handling-wcf-service-exceptions-using-fault-contracts