TerminatingOperationBehavior.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 / Dispatcher / TerminatingOperationBehavior.cs / 1 / TerminatingOperationBehavior.cs

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

namespace System.ServiceModel.Dispatcher 
{
    using System.ServiceModel.Channels; 
 
    internal class TerminatingOperationBehavior
    { 
        static void AbortChannel(object state)
        {
            ((IChannel)state).Abort();
        } 

        public static TerminatingOperationBehavior CreateIfNecessary(DispatchRuntime dispatch) 
        { 
            if (IsTerminatingOperationBehaviorNeeded(dispatch))
            { 
                return new TerminatingOperationBehavior();
            }
            else
            { 
                return null;
            } 
        } 

        static bool IsTerminatingOperationBehaviorNeeded(DispatchRuntime dispatch) 
        {
            for (int i = 0; i < dispatch.Operations.Count; i++)
            {
                DispatchOperation operation = dispatch.Operations[i]; 

                if (operation.IsTerminating) 
                { 
                    return true;
                } 
            }

            return false;
        } 

        internal void AfterReply(ref MessageRpc rpc) 
        { 
            if (rpc.Operation.IsTerminating && rpc.Channel.HasSession)
            { 
                IOThreadTimer timer = new IOThreadTimer(TerminatingOperationBehavior.AbortChannel,
                                                        rpc.Channel.Binder.Channel, false);

                timer.Set(rpc.Channel.CloseTimeout); 
            }
        } 
 
        internal static void AfterReply(ref ProxyRpc rpc)
        { 
            if (rpc.Operation.IsTerminating && rpc.Channel.HasSession)
            {
                IChannel sessionChannel = rpc.Channel.Binder.Channel;
                rpc.Channel.Close(rpc.TimeoutHelper.RemainingTime()); 
            }
        } 
    } 
}

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