MessageDispatch.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 / TransactionBridge / Microsoft / Transactions / Wsat / Messaging / MessageDispatch.cs / 1 / MessageDispatch.cs

                            //------------------------------------------------------------------------------ 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------------------------

// Implement generic reception of datagram and request messages 

using System; 
using System.ServiceModel.Channels; 
using System.Diagnostics;
using System.ServiceModel; 
using Microsoft.Transactions.Wsat.Protocol;

using DiagnosticUtility = Microsoft.Transactions.Bridge.DiagnosticUtility;
 
namespace Microsoft.Transactions.Wsat.Messaging
{ 
    abstract class DatagramMessageDispatcher 
    {
        ProtocolVersion protocolVersion; 

        protected DatagramMessageDispatcher(ProtocolVersion protocolVersion)
        {
            this.protocolVersion = protocolVersion; 
        }
 
        protected abstract DatagramProxy CreateFaultProxy(EndpointAddress to); 

        protected void OnMessageException(Message message, CommunicationException exception) 
        {
            DebugTrace.Trace (
                TraceLevel.Warning,
                "{0} - {1} reading datagram with action {2}: {3}", 
                this.GetType().Name, exception.GetType().Name, message.Headers.Action, exception.Message);
 
            EndpointAddress sendTo = Library.GetFaultToHeader(message.Headers, this.protocolVersion); 
            if (sendTo == null)
            { 
                DebugTrace.Trace (
                    TraceLevel.Warning,
                    "Ignoring invalid datagram - a fault-to header could not be obtained"
                    ); 
            }
            else 
            { 
                DatagramProxy proxy = null;
                try 
                {
                    proxy = CreateFaultProxy(sendTo);
                }
                catch (CreateChannelFailureException e) 
                {
                    DiagnosticUtility.ExceptionUtility.TraceHandledException(e, TraceEventType.Warning); 
 
                    DebugTrace.Trace (TraceLevel.Warning,
                                      "Ignoring invalid datagram: {0}", 
                                      e.Message);
                }

                if (proxy != null) 
                {
                    try 
                    { 
                        IAsyncResult ar = proxy.BeginSendFault (message.Headers.MessageId,
                                                                Faults.Version(this.protocolVersion).InvalidParameters, null, null); 
                        proxy.EndSendMessage (ar);

                        if (DebugTrace.Warning)
                        { 
                            DebugTrace.Trace (
                                TraceLevel.Warning, 
                                "Sent InvalidParameters fault to {0}", 
                                proxy.To.Uri
                                ); 
                        }
                    }
                    catch (WsatSendFailureException e)
                    { 
                        DiagnosticUtility.ExceptionUtility.TraceHandledException(e, TraceEventType.Warning);
 
                        if (DebugTrace.Warning) 
                        {
                            DebugTrace.Trace ( 
                                TraceLevel.Warning,
                                "{0} sending InvalidParameters fault to {1}: {2}",
                                e.GetType().Name, proxy.To.Uri, e.Message);
                        } 
                    }
                    finally 
                    { 
                        proxy.Release();
                    } 
                }
            }
        }
    } 

    abstract class RequestMessageDispatcher 
    { 
        protected abstract void SendFaultReply (RequestAsyncResult result, Fault fault);
 
        protected void OnMessageException (RequestAsyncResult result, Message message, CommunicationException exception, Fault fault)
        {
            DebugTrace.Trace (
                TraceLevel.Warning, 
                "{0} - {1} reading request with action {2}: {3}",
                this.GetType().Name, exception.GetType().Name, message.Headers.Action, exception.Message); 
 
            SendFaultReply (result, fault);
 
            DebugTrace.Trace (TraceLevel.Warning, "Replied with {0} fault", fault.Code.Name);
        }
    }
} 

// 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