Tutorial by Examples

It's important to handle exceptions in your service. When developing the service, you can set the WCF to provide more detailed information, adding this tag to configuration file, usually Web.config: <serviceDebug includeExceptionDetailInFaults="true"/> This tag must be placed w...
You can handle exceptions and throw a most friendly message like 'Unavailable service' throwing a FaultException: try { // your service logic here } catch (Exception ex) { // You can do something here, like log the original exception throw new FaultException("There was a pro...
The FaultException can also includes a FaultCode, that is a string data you can use to pass additional information, so the client can be able to distinguish different exceptions: try { // your service logic here } catch (Exception ex) { throw new FaultException("There was a proble...
To decouple and reuse the same error logging code for all your services you need two boilerplate classes and tuck them away in a library somewhere. ErrorhandlerAttribute implementing IServiceBehavior. FaultErrorhandler implementing IErrorhandler which logs all the exceptions. [AttributeUsage(Attr...
It is sometimes useful to integrate a custom error logging framework to ensure all exceptions are logged. [ServiceContract] [ErrorHandler] public interface IMyService { } [AttributeUsage(AttributeTargets.Interface)] public class CustomErrorHandler : Attribute, IContractBehavior, IE...

Page 1 of 1