Skip to Main Content
Programming WCF Services
book

Programming WCF Services

by Juval Lowy
February 2007
Intermediate to advanced content levelIntermediate to advanced
634 pages
16h 1m
English
O'Reilly Media, Inc.
Content preview from Programming WCF Services

Faults

  1. Never use a proxy instance after an exception, even if you catch that exception.

  2. Do not reuse the callback channel after an exception even if you catch that exception, as the channel may be faulted.

  3. Use the FaultContractAttribute with exception classes, as opposed to mere serializable types:

    //Avoid:
    [OperationContract]
    [FaultContract(typeof(double))]
    double Divide(double number1,double number2);
    
    //Correct:
    [OperationContract]
    [FaultContract(typeof(DivideByZeroException))]
    double Divide(double number1,double number2);
  4. Avoid lengthy processing such as logging in IErrorHandler.ProvideFault( ).

  5. With both service classes and callback classes, set IncludeExceptionDetailInFaults to true in debug sessions, either in the config file or programmatically:

    public class DebugHelper
    {
       public const bool IncludeExceptionDetailInFaults =
    #if DEBUG
          true;
    #else
          false;
    #endif
    }
    [ServiceBehavior(IncludeExceptionDetailInFaults =
                     DebugHelper.IncludeExceptionDetailInFaults)]
    class MyService : IMyContract
    {...}
  6. In release builds, do not return unknown exceptions as faults except in diagnostic scenarios.

  7. Consider using the ErrorHandlerBehaviorAttribute on the service for both promoting exceptions to fault contracts and automatic error logging:

    [ErrorHandlerBehavior]
    class MyService : IMyContract
    {...}
  8. Consider using the CallbackErrorHandlerBehaviorAttribute on the callback client for both promoting exceptions to fault contracts and automatic error logging:

    [CallbackErrorHandlerBehavior(typeof(MyClient))] public ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming WCF Services, 3rd Edition

Programming WCF Services, 3rd Edition

Juval Lowy
Mastering ASP.NET Web API

Mastering ASP.NET Web API

Mithun Pattankar, Malendra Hurbuns

Publisher Resources

ISBN: 0596526997Supplemental ContentErrata Page