250 likes | 482 Views
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.
E N D
INDIA │ 22-24 November2010 virtual techdays Exception Handling in WCF Jebarson Jebamony│ Consultant, Microsoft
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
INDIA │ 22-24 November2010 virtual techdays Exception Handling in WCF Introduction
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
INDIA │ 22-24 November2010 virtual techdays DEMO : Exception Handling In WCF Application Overview
INDIA │ 22-24 November2010 virtual techdays Demo : Application Overview High Level Diagram Proxy
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.
INDIA │ 22-24 November2010 virtual techdays Contd.. Introduction Exception handling in WCF vs. WS.
INDIA │ 22-24 November2010 virtual techdays DEMO: Exception Handling In WCF GetUser│Default exception handling
INDIA │ 22-24 November2010 virtual techdays What happened on Demo? Introduction Exception handling in WCF & guidelines
INDIA │ 22-24 November2010 virtual techdays Exception Handling in WCF Fault Exceptions
INDIA │ 22-24 November2010 virtual techdays Fault Exceptions Architecture
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
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
INDIA │ 22-24 November2010 virtual techdays DEMO: Exception Handling In WCF GetUser│Fault Exception handling guidelines & scenarios
INDIA │ 22-24 November2010 virtual techdays What happened on Demo? Fault Exceptions Using FaultException
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
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.
INDIA │ 22-24 November2010 virtual techdays DEMO: Exception Handling In WCF GetUser│Custom fault exception handling
INDIA │ 22-24 November2010 virtual techdays Exception Handling in WCF Custom Error Handler
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
INDIA │ 22-24 November2010 virtual techdays Custom Error Handler Using IErrorHandler
INDIA │ 22-24 November2010 virtual techdays DEMO: Exception Handling In WCF GetUser│Custom error handler
INDIA │ 22-24 November2010 virtual techdays Exception Handling In WCF Questions & Answers
THANKS│22-24 November2010 virtual techdays jebarv@microsoft.com │ http://jebarson.info