![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Fault contracts Good Evening All, I am defining a fault handling system to be used by all of our services. I recently attended a lecture that covered this matter presented by Michele Bustamante. During the workshop, she outlined three approaches to handling faults (see http://travisspencer.com/blog/2007/1...g_fault_c.html). The approach that we've decided upon is to define two basic fault types -- one for service-side and another for client-side problems. To this end, I've created a class library that consists primary of the following C# code. I am wondering if anyone has any comments on the code. In particular, I'm curious what others have to say about the XML namespaces, the Action property (to be used when creating a FaultMessage), the conditional compiled code, and other little details. TIA! -- Regards, Travis Spencer namespace MyCompany.MyProject.Common { using System; using System.Runtime.Serialization; using System.ServiceModel; [ DataContract(Namespace = "http://schemas.mycompany.com/ myproject/common/faultcontracts/2007/11"), KnownType(typeof(SenderFault)), KnownType(typeof(ReceiverFault)), ] public class BaseFault { public BaseFault() { } public BaseFault(Exception ex) { Message = ex.Message; Code = int.MaxValue; // Default code which means that the sky is falling. #if DEBUG if (ex.InnerException == null) Details = ex.StackTrace; else Details = "Base Exception Message:\n" + ex.GetBaseException().Message + "\n" + "Stack Trace:\n" + ex.StackTrace; #endif } public BaseFault(Exception ex, int code) : this(ex) { Code = code; } [DataMember(IsRequired = true)] public int? Code { get; set; } [DataMember(IsRequired = true)] public string Message { get; set; } [DataMember(IsRequired = true)] public string Details { get; set; } } [DataContract(Namespace = "http://schemas.mycompany.com/myproject/ common/faultcontracts/2007/11")] public class SenderFault : BaseFault { public SenderFault() { } public SenderFault(Exception ex) : base(ex) { } public SenderFault(Exception ex, int code) : base(ex, code) { } // This makes the mutable fault code reference type "immutable". public static FaultCode FaultCode { get { if (faultCode == null) faultCode = FaultCode.CreateSenderFaultCode("blort", "http://schemas.mycompany.com/myproject/common/ faultcontracts/senderfault/2007/11"); return faultCode; } } // Immutablility enforced by the run-time. public static readonly string Action = "http://schemas.mycompany.com/myproject/common/ faultcontracts/senderfault"; private static FaultCode faultCode; } [DataContract(Namespace = "http://schemas.mycompany.com/myproject/ common/faultcontracts/2007/11")] public class ReceiverFault : BaseFault { public ReceiverFault() { } public ReceiverFault(Exception ex) : base(ex) { } public ReceiverFault(Exception ex, int code) : base(ex, code) { } public static FaultCode FaultCode { get { if (faultCode == null) faultCode = FaultCode.CreateReceiverFaultCode( new FaultCode("Database", "http://schemas.mycompany.com/myproject/ common/faultcontracts/receiverfault/2007/11")); return faultCode; } } public static readonly string Action = "http://schemas.mycompany.com/myproject/common/ faultcontracts/receiverfault/"; private static FaultCode faultCode; } } |
My System Specs![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| fault | joe72 | Vista mail | 1 | 12-30-2007 10:12 AM |
| Windows Contracts | n4wi | Vista General | 4 | 08-07-2007 09:27 PM |