Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Indigo

Vista - Fault contracts

 
 
Old 11-19-2007   #1 (permalink)
travislspencer


 
 

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


Similar Threads
Thread Forum
Office 2007 Outlook Contracts will not open in Vista Windows Mail Vista mail
Windows Contracts Vista General


Vista Forums 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 Ltd

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