Skip to Content
Programming WCF Services, 3rd Edition
book

Programming WCF Services, 3rd Edition

by Juval Lowy
August 2010
Intermediate to advanced
908 pages
26h 22m
English
O'Reilly Media, Inc.
Content preview from Programming WCF Services, 3rd Edition

Faults

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

  2. Do not use the using statement on a proxy.

  3. Avoid fault contracts and allow WCF to mask the error.

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

  5. Use the FaultContract attribute 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);
  6. Avoid lengthy processing such as logging in IErrorHandler.ProvideFault().

  7. 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
    {...}
  8. In release builds, do not return unknown exceptions as faults except in diagnostic scenarios.

  9. Consider using the ErrorHandlerBehavior attribute on the service, both for promoting exceptions to fault contracts and for automatic error logging:

    [ErrorHandlerBehavior]
    class MyService : IMyContract
    {...}
  10. Consider using the CallbackErrorHandlerBehaviorAttribute on the callback client, both for promoting exceptions ...

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, 4th Edition

Programming WCF Services, 4th Edition

Juval Lowy, Michael Montgomery
Programming .NET Security

Programming .NET Security

Adam Freeman, Allen Jones

Publisher Resources

ISBN: 9781449382476Supplemental ContentErrata Page