WsatTransactionHeader.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Transactions / WsatTransactionHeader.cs / 1 / WsatTransactionHeader.cs

                            //------------------------------------------------------------ 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------
namespace System.ServiceModel.Transactions
{ 
    using System;
    using System.ServiceModel.Channels; 
    using System.Diagnostics; 
    using System.ServiceModel;
    using System.Transactions; 
    using System.Xml;

    using Microsoft.Transactions.Wsat.Messaging;
    using Microsoft.Transactions.Wsat.Protocol; 

    class WsatTransactionHeader : MessageHeader 
    { 
        string wsatHeaderElement;
        string wsatNamespace; 
        CoordinationContext context;

        public WsatTransactionHeader(CoordinationContext context, ProtocolVersion protocolVersion)
        { 
            this.context = context;
            CoordinationStrings coordinationStrings = CoordinationStrings.Version(protocolVersion); 
            this.wsatHeaderElement = coordinationStrings.CoordinationContext; 
            this.wsatNamespace = coordinationStrings.Namespace;
        } 

        public override bool MustUnderstand
        {
            get { return true; } 
        }
 
        public override string Name 
        {
            get { return wsatHeaderElement; } 
        }

        public override string Namespace
        { 
            get { return wsatNamespace; }
        } 
 
        public static CoordinationContext GetCoordinationContext(Message message, ProtocolVersion protocolVersion)
        { 
            CoordinationStrings coordinationStrings = CoordinationStrings.Version(protocolVersion);
            string locWsatHeaderElement = coordinationStrings.CoordinationContext;
            string locWsatNamespace = coordinationStrings.Namespace;
 
            int index;
            try 
            { 
                index = message.Headers.FindHeader(locWsatHeaderElement, locWsatNamespace);
            } 
            catch (MessageHeaderException e)
            {
                DiagnosticUtility.ExceptionUtility.TraceHandledException(e, TraceEventType.Warning);
                return null; 
            }
            if (index < 0) 
                return null; 

            CoordinationContext context; 
            XmlDictionaryReader reader = message.Headers.GetReaderAtHeader(index);
            using (reader)
            {
                context = GetCoordinationContext(reader, protocolVersion); 
            }
 
            MessageHeaderInfo header = message.Headers[index]; 
            if (!message.Headers.UnderstoodHeaders.Contains(header))
            { 
                message.Headers.UnderstoodHeaders.Add(header);
            }

            return context; 
        }
 
        protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion) 
        {
            this.context.WriteContent(writer); 
        }

        public static CoordinationContext GetCoordinationContext(XmlDictionaryReader reader, ProtocolVersion protocolVersion)
        { 
            CoordinationXmlDictionaryStrings coordinationXmlDictionaryStrings =
                                                CoordinationXmlDictionaryStrings.Version(protocolVersion); 
            try 
            {
                return CoordinationContext.ReadFrom(reader, 
                                                    coordinationXmlDictionaryStrings.CoordinationContext,
                                                    coordinationXmlDictionaryStrings.Namespace,
                                                    protocolVersion);
            } 
            catch (InvalidCoordinationContextException e)
            { 
                DiagnosticUtility.ExceptionUtility.TraceHandledException(e, TraceEventType.Error); 
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new TransactionException(SR.GetString(SR.WsatHeaderCorrupt), e));
            } 
        }

        public static void WriteElement(XmlDictionaryWriter writer,
                                        CoordinationContext context, 
                                        ProtocolVersion protocolVersion)
        { 
            CoordinationXmlDictionaryStrings coordinationXmlDictionaryStrings = 
                                                CoordinationXmlDictionaryStrings.Version(protocolVersion);
            context.WriteTo(writer, 
                            coordinationXmlDictionaryStrings.CoordinationContext,
                            coordinationXmlDictionaryStrings.Namespace);
        }
 
        public static bool IsStartElement(XmlDictionaryReader reader, ProtocolVersion protocolVersion)
        { 
            CoordinationXmlDictionaryStrings coordinationXmlDictionaryStrings = 
                                                CoordinationXmlDictionaryStrings.Version(protocolVersion);
 
            return reader.IsStartElement(coordinationXmlDictionaryStrings.CoordinationContext,
                                         coordinationXmlDictionaryStrings.Namespace);
        }
    } 
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK