1 / 25

virtual techdays

INDIA │ 22-24 November 2010. virtual techdays. Exception Handling in WCF. Jebarson Jebamony │ Consultant, Microsoft. INDIA │ 22-24 November 2010. virtual techdays. Introduction Exceptions and handling. Exception handling in WCF vs WS. Exception handling in WCF & guidelines.

iolani
Download Presentation

virtual techdays

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. INDIA │ 22-24 November2010 virtual techdays Exception Handling in WCF Jebarson Jebamony│ Consultant, Microsoft

  2. INDIA │ 22-24 November2010 virtual techdays • Introduction • Exceptions and handling. • Exception handling in WCF vs WS. • Exception handling in WCF & guidelines. • Fault Exceptions • Using FaultException, FaultReason and FaultCode. • Strong custom type fault exceptions. • Custom Error Handler • Using IErrorHandler • Questions & Answers S E S S I O N A G E N D A

  3. INDIA │ 22-24 November2010 virtual techdays Exception Handling in WCF Introduction

  4. INDIA │ 22-24 November2010 virtual techdays • Exceptions are inevitable. • Exception handling should be included by design. • The more the exception handling, the more the robust. • Crash recovery for unhandled exceptions. • Testing applications against exceptions. Introduction Exceptions and handling

  5. INDIA │ 22-24 November2010 virtual techdays DEMO : Exception Handling In WCF Application Overview

  6. INDIA │ 22-24 November2010 virtual techdays Demo : Application Overview High Level Diagram Proxy

  7. INDIA │ 22-24 November2010 virtual techdays • WS can never return the exception stack trace to the caller. • Custom code has to be written to return the exception. • All the exceptions will be returned as Fault in WCF. Introduction Exception handling in WCF vs. WS.

  8. INDIA │ 22-24 November2010 virtual techdays Contd.. Introduction Exception handling in WCF vs. WS.

  9. INDIA │ 22-24 November2010 virtual techdays DEMO: Exception Handling In WCF GetUser│Default exception handling

  10. INDIA │ 22-24 November2010 virtual techdays What happened on Demo? Introduction Exception handling in WCF & guidelines

  11. INDIA │ 22-24 November2010 virtual techdays Exception Handling in WCF Fault Exceptions

  12. INDIA │ 22-24 November2010 virtual techdays Fault Exceptions Architecture

  13. INDIA │ 22-24 November2010 virtual techdays • FaultCode Fault Code Differentiates the fault from other; “Name” is used as a differentiator. “SubCode” is used to denote the inner fault code or exception. Static method “CreateReceiverFaultCode” is used to create a fault code when the fault occurred because of the reciever (server). Static method “CreateSenderFaultCode” is used to create a fault code when the fault occurred because of the sender (client). Flags are available to differentiate if the fault is of receiver / sender / pre-defined. Fault Exceptions FaultCode

  14. INDIA │ 22-24 November2010 virtual techdays • FaultReason Fault Reason Used as a type to notify the reason for the fault occurance. There can be a single / multiple reason text (“FaultReasonText”) provided. Multi cultural text can be added to the reason and provides the support to bind the text to the UI with respect to the culture set on the UI. Fault Exceptions FaultReason

  15. INDIA │ 22-24 November2010 virtual techdays DEMO: Exception Handling In WCF GetUser│Fault Exception handling guidelines & scenarios

  16. INDIA │ 22-24 November2010 virtual techdays What happened on Demo? Fault Exceptions Using FaultException

  17. INDIA │ 22-24 November2010 virtual techdays • Remember to switch on “includeExceptionDetailInFaults” while debugging. • Also remember to switch off “includeExceptionDetailInFaults” on production. All exceptions should be converted to faults while on production. • Ensure that the faults / exceptions are called in the reverse inheritance order to ensure that exceptions are caught on the right catch block. Fault Exceptions Points to remember

  18. INDIA │ 22-24 November2010 virtual techdays • CustomType FaultException<T> Allows to define and pass a custom data contract type to the fault exception. Inherits from FaultException and therefore has to be caught before the base is caught. Requires the types expected to be defined in the operation contract. If not defined, the custom exception will be considered as “FaultException”. Note: Remember as of now the MSDN shows that the reason is not mandatory for you to raise a FaultException<T>, which is incorrect. Fault Exceptions Strong custom type fault exceptions.

  19. INDIA │ 22-24 November2010 virtual techdays DEMO: Exception Handling In WCF GetUser│Custom fault exception handling

  20. INDIA │ 22-24 November2010 virtual techdays Exception Handling in WCF Custom Error Handler

  21. INDIA │ 22-24 November2010 virtual techdays • Allows one to dictate the way the exception has to be handled when it raises. • Gives the service programmer less control over the way the exception is bubbled. • “ProvideFault” is the method which allows to raise the fault message with your own freedom. The logic on which fault to be raised is done here. • “HandleError” is mostly used for logging the exceptions and writing failure recovery mechanism. The programmer can return a flag stating whether to crash the session or continue. • Custom error handler needs an behavior extension defined to provide control to it for a needed service. Custom Error Handler Using IErrorHandler

  22. INDIA │ 22-24 November2010 virtual techdays Custom Error Handler Using IErrorHandler

  23. INDIA │ 22-24 November2010 virtual techdays DEMO: Exception Handling In WCF GetUser│Custom error handler

  24. INDIA │ 22-24 November2010 virtual techdays Exception Handling In WCF Questions & Answers

  25. THANKS│22-24 November2010 virtual techdays jebarv@microsoft.com │ http://jebarson.info

More Related