Handling exceptions the right way in WCF (part 1)
Control over exceptions is very important in WCF because exceptions can contain a lot of information about the internals of your service potentially leading to security issues. WCF allows to define not only data, service or message contracts but also fault contracts. Fault contracts are used to materialize potential exceptions in the metadata of your service. To do that, you just have to declare on your service contract which exception might be raised by a specific method. Here is a simple service contract : [ServiceContract] public interface IService1 { [OperationContract] [FaultContract(typeof(SomeFault))] void DoSomething(); } Here, we are telling the WCF runtime to expose a fault contract in the service metadata. The object containing the fault detail is named SomeFault. Here is the definition of the SomeFault class : [DataContract] public class SomeFault { [DataMember] public String SomeInfo { get; set; } } As you see, SomeFault is a data contract. Its use is only t...