- wcfhelpers.zip
- BuildCommands
- WCFHelpers.Client
- WCFHelpers.Service
- WCFHelpers.sln
- WCFHelpers.Test.Contract
- WCFHelpers.Test.Service
- WCFHelpers.Test.SilverlightClient.Web
- WCFHelpers.Test.SilverlightClient
- WCFHelpers.Test.WindowsClient
|
using System.ServiceModel;
using System.ServiceModel.Channels;
using WCFHelpers.Client;
namespace WCFHelpers
{
public static class Global
{
public enum FaultHandling
{
/// <summary>
/// The client cannot handle faults Fault handling
/// </summary>
None,
Simple,
FullContract,
}
public const string FaultHandlingNS = "urn:Silverlight-FaultHandler";
/// <summary>
/// Adds a message header to the current operation stating that the client does not support standard Fault contracting
/// </summary>
/// <param name="Context">The active <see cref="OperationContext"/></param>
public static void SetNoFaultHandling(OperationContext Context)
{
//Remove any previous Header
int iHeader = Context.OutgoingMessageHeaders.FindHeader("NoFaultHandling", FaultHandlingNS);
if (iHeader >= 0)
Context.OutgoingMessageHeaders.RemoveAt(iHeader);
Context.OutgoingMessageHeaders.Add(MessageHeader.CreateHeader("NoFaultHandling", FaultHandlingNS, true));
}
/// <summary>
/// Checks the current operation for a message header stating if it can handle standard fault contracts
/// </summary>
/// <param name="Context">The active <see cref="OperationContext"/></param>
/// <returns>false if the current operation has explicitly stated it cannot handle faults, true otherwise</returns>
public static bool HandlesFaults(OperationContext Context)
{
int iHeader = Context.IncomingMessageHeaders.FindHeader("NoFaultHandling", FaultHandlingNS);
if (iHeader < 0)
return true;
return !Context.IncomingMessageHeaders.GetHeader<bool>(iHeader);
}
/// <summary>
/// Adds <see cref="FaultDetail"/> to the current Outgoing message headers
/// </summary>
/// <param name="Fault">The <see cref="FaultDetail"/> to add to the message</param>
/// <param name="Context">the active <see cref="OperationContext"/></param>
public static void SetFault(FaultDetail Fault, OperationContext Context)
{
Context.OutgoingMessageHeaders.Add(MessageHeader.CreateHeader("Fault", FaultHandlingNS, Fault));
}
/// <summary>
/// Extracts and returns a <see cref="FaultDetail"/> object from the message headers if present
/// </summary>
/// <param name="Context">The active <see cref="OperationContext"/></param>
/// <returns>A <see cref="FaultDetail"/> if it was present in the returning message</returns>
public static FaultDetail GetFault(OperationContext Context)
{
int iHeader = Context.IncomingMessageHeaders.FindHeader("Fault", FaultHandlingNS);
if (iHeader >= 0)
return Context.IncomingMessageHeaders.GetHeader<FaultDetail>(iHeader);
return null;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.