Windows Vista Forums
Vista Forums Home Join Vista Forums Webcasts Vista Tutorials Tags

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.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Indigo

Fault contracts

Update your Vista Drivers Update Your Drivers Now!!
 
 
Thread Tools Display Modes
Old 11-19-2007   #1 (permalink)
travislspencer
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 SpecsSystem Spec
 

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


Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51