Example #1
0
        private void Dispatch()
        {
            ListenerChannel    channel     = _channel;
            SessionIdleManager idleManager = _idleManager;

            _channel     = null;
            _idleManager = null;

            try
            {
                if (channel != null)
                {
                    ChannelHandler handler = new ChannelHandler(_listenerBinder.MessageVersion, channel.Binder, this, idleManager);

                    if (!channel.Binder.HasSession)
                    {
                        _channelDispatcher.Channels.Add(channel.Binder.Channel);
                    }

                    if (channel.Binder is DuplexChannelBinder)
                    {
                        DuplexChannelBinder duplexChannelBinder = channel.Binder as DuplexChannelBinder;
                        duplexChannelBinder.ChannelHandler      = handler;
                        duplexChannelBinder.DefaultCloseTimeout = this.DefaultCloseTimeout;

                        if (_timeouts == null)
                        {
                            duplexChannelBinder.DefaultSendTimeout = ServiceDefaults.SendTimeout;
                        }
                        else
                        {
                            duplexChannelBinder.DefaultSendTimeout = _timeouts.SendTimeout;
                        }
                    }

                    ChannelHandler.Register(handler);
                    channel     = null;
                    idleManager = null;
                }
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
                this.HandleError(e);
            }
            finally
            {
                if (channel != null)
                {
                    channel.Binder.Channel.Abort();
                    if (idleManager != null)
                    {
                        idleManager.CancelTimer();
                    }
                }
            }
        }
        bool TransactedAccept(out Transaction tx)
        {
            tx = null;

            try
            {
                tx = TransactionBehavior.CreateTransaction(this.ChannelDispatcher.TransactionIsolationLevel, this.ChannelDispatcher.TransactionTimeout);

                IChannelBinder binder = null;
                using (TransactionScope scope = new TransactionScope(tx))
                {
                    TimeSpan acceptTimeout = TimeoutHelper.Min(this.ChannelDispatcher.TransactionTimeout, this.ChannelDispatcher.DefaultCommunicationTimeouts.ReceiveTimeout);
                    if (!this.acceptor.TryAccept(TransactionBehavior.NormalizeTimeout(acceptTimeout), out binder))
                    {
                        return(false);
                    }
                    scope.Complete();
                }
                if (null != binder)
                {
                    this.channel     = new ListenerChannel(binder);
                    this.idleManager = SessionIdleManager.CreateIfNeeded(this.channel.Binder, this.channelDispatcher.DefaultCommunicationTimeouts.ReceiveTimeout);
                    return(true);
                }
                else
                {
                    this.AcceptedNull();
                    tx = null;
                    return(false);
                }
            }
            catch (CommunicationException e)
            {
                if (null != tx)
                {
                    try
                    {
                        tx.Rollback();
                    }
                    catch (TransactionException ex)
                    {
                        DiagnosticUtility.TraceHandledException(ex, TraceEventType.Information);
                    }
                }
                tx = null;

                DiagnosticUtility.TraceHandledException(e, TraceEventType.Information);

                return(false);
            }
            catch (TransactionException e)
            {
                tx = null;

                DiagnosticUtility.TraceHandledException(e, TraceEventType.Information);

                return(false);
            }
        }
Example #3
0
        private void Dispatch()
        {
            ListenerChannel channel = this.channel;

            ServiceChannel.SessionIdleManager idleManager = this.idleManager;
            this.channel     = null;
            this.idleManager = null;
            try
            {
                if (channel != null)
                {
                    ChannelHandler handler = new ChannelHandler(this.listenerBinder.MessageVersion, channel.Binder, this.throttle, this, channel.Throttle != null, this.wrappedTransaction, idleManager);
                    if (!channel.Binder.HasSession)
                    {
                        this.channelDispatcher.Channels.Add(channel.Binder.Channel);
                    }
                    if (channel.Binder is DuplexChannelBinder)
                    {
                        DuplexChannelBinder binder = channel.Binder as DuplexChannelBinder;
                        binder.ChannelHandler      = handler;
                        binder.DefaultCloseTimeout = this.DefaultCloseTimeout;
                        if (this.timeouts == null)
                        {
                            binder.DefaultSendTimeout = ServiceDefaults.SendTimeout;
                        }
                        else
                        {
                            binder.DefaultSendTimeout = this.timeouts.SendTimeout;
                        }
                    }
                    ChannelHandler.Register(handler);
                    channel     = null;
                    idleManager = null;
                }
            }
            catch (Exception exception)
            {
                if (Fx.IsFatal(exception))
                {
                    throw;
                }
                this.HandleError(exception);
            }
            finally
            {
                if (channel != null)
                {
                    channel.Binder.Channel.Abort();
                    if ((this.throttle != null) && this.channelDispatcher.Session)
                    {
                        this.throttle.DeactivateChannel();
                    }
                    if (idleManager != null)
                    {
                        idleManager.CancelTimer();
                    }
                }
            }
        }
Example #4
0
 private bool HandleEndAccept(IAsyncResult result)
 {
     this.channel = this.CompleteAccept(result);
     if (this.channel != null)
     {
         this.idleManager = ServiceChannel.SessionIdleManager.CreateIfNeeded(this.channel.Binder, this.channelDispatcher.DefaultCommunicationTimeouts.ReceiveTimeout);
         return(this.AcquireThrottle());
     }
     this.DoneAccepting();
     return(true);
 }
        bool HandleEndAccept(IAsyncResult result)
        {
            this.channel = this.CompleteAccept(result);

            if (this.channel != null)
            {
                Fx.Assert(this.idleManager == null, "There cannot be an existing idle manager");
                this.idleManager = SessionIdleManager.CreateIfNeeded(this.channel.Binder, this.channelDispatcher.DefaultCommunicationTimeouts.ReceiveTimeout);
            }
            else
            {
                this.DoneAccepting();
                return(true);
            }

            return(this.AcquireThrottle());
        }
 private bool TransactedAccept(out Transaction tx)
 {
     tx = null;
     try
     {
         tx = TransactionBehavior.CreateTransaction(this.ChannelDispatcher.TransactionIsolationLevel, this.ChannelDispatcher.TransactionTimeout);
         IChannelBinder channelBinder = null;
         using (TransactionScope scope = new TransactionScope(tx))
         {
             TimeSpan timeout = TimeoutHelper.Min(this.ChannelDispatcher.TransactionTimeout, this.ChannelDispatcher.DefaultCommunicationTimeouts.ReceiveTimeout);
             if (!this.acceptor.TryAccept(TransactionBehavior.NormalizeTimeout(timeout), out channelBinder))
             {
                 return false;
             }
             scope.Complete();
         }
         if (channelBinder != null)
         {
             this.channel = new ListenerChannel(channelBinder);
             this.idleManager = ServiceChannel.SessionIdleManager.CreateIfNeeded(this.channel.Binder, this.channelDispatcher.DefaultCommunicationTimeouts.ReceiveTimeout);
             return true;
         }
         this.AcceptedNull();
         tx = null;
         return false;
     }
     catch (CommunicationException exception)
     {
         if (null != tx)
         {
             try
             {
                 tx.Rollback();
             }
             catch (TransactionException exception2)
             {
                 if (DiagnosticUtility.ShouldTraceInformation)
                 {
                     DiagnosticUtility.ExceptionUtility.TraceHandledException(exception2, TraceEventType.Information);
                 }
             }
         }
         tx = null;
         if (DiagnosticUtility.ShouldTraceInformation)
         {
             DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Information);
         }
         return false;
     }
     catch (TransactionException exception3)
     {
         tx = null;
         if (DiagnosticUtility.ShouldTraceInformation)
         {
             DiagnosticUtility.ExceptionUtility.TraceHandledException(exception3, TraceEventType.Information);
         }
         return false;
     }
 }
 private bool HandleEndAccept(IAsyncResult result)
 {
     this.channel = this.CompleteAccept(result);
     if (this.channel != null)
     {
         this.idleManager = ServiceChannel.SessionIdleManager.CreateIfNeeded(this.channel.Binder, this.channelDispatcher.DefaultCommunicationTimeouts.ReceiveTimeout);
         return this.AcquireThrottle();
     }
     this.DoneAccepting();
     return true;
 }
 private void Dispatch()
 {
     ListenerChannel channel = this.channel;
     ServiceChannel.SessionIdleManager idleManager = this.idleManager;
     this.channel = null;
     this.idleManager = null;
     try
     {
         if (channel != null)
         {
             ChannelHandler handler = new ChannelHandler(this.listenerBinder.MessageVersion, channel.Binder, this.throttle, this, channel.Throttle != null, this.wrappedTransaction, idleManager);
             if (!channel.Binder.HasSession)
             {
                 this.channelDispatcher.Channels.Add(channel.Binder.Channel);
             }
             if (channel.Binder is DuplexChannelBinder)
             {
                 DuplexChannelBinder binder = channel.Binder as DuplexChannelBinder;
                 binder.ChannelHandler = handler;
                 binder.DefaultCloseTimeout = this.DefaultCloseTimeout;
                 if (this.timeouts == null)
                 {
                     binder.DefaultSendTimeout = ServiceDefaults.SendTimeout;
                 }
                 else
                 {
                     binder.DefaultSendTimeout = this.timeouts.SendTimeout;
                 }
             }
             ChannelHandler.Register(handler);
             channel = null;
             idleManager = null;
         }
     }
     catch (Exception exception)
     {
         if (Fx.IsFatal(exception))
         {
             throw;
         }
         this.HandleError(exception);
     }
     finally
     {
         if (channel != null)
         {
             channel.Binder.Channel.Abort();
             if ((this.throttle != null) && this.channelDispatcher.Session)
             {
                 this.throttle.DeactivateChannel();
             }
             if (idleManager != null)
             {
                 idleManager.CancelTimer();
             }
         }
     }
 }
Example #9
0
        private void Dispatch()
        {
            ListenerChannel channel = _channel;
            SessionIdleManager idleManager = _idleManager;
            _channel = null;
            _idleManager = null;

            try
            {
                if (channel != null)
                {
                    ChannelHandler handler = new ChannelHandler(_listenerBinder.MessageVersion, channel.Binder, this, idleManager);

                    if (!channel.Binder.HasSession)
                    {
                        _channelDispatcher.Channels.Add(channel.Binder.Channel);
                    }

                    if (channel.Binder is DuplexChannelBinder)
                    {
                        DuplexChannelBinder duplexChannelBinder = channel.Binder as DuplexChannelBinder;
                        duplexChannelBinder.ChannelHandler = handler;
                        duplexChannelBinder.DefaultCloseTimeout = this.DefaultCloseTimeout;

                        if (_timeouts == null)
                            duplexChannelBinder.DefaultSendTimeout = ServiceDefaults.SendTimeout;
                        else
                            duplexChannelBinder.DefaultSendTimeout = _timeouts.SendTimeout;
                    }

                    ChannelHandler.Register(handler);
                    channel = null;
                    idleManager = null;
                }
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
                this.HandleError(e);
            }
            finally
            {
                if (channel != null)
                {
                    channel.Binder.Channel.Abort();
                    if (idleManager != null)
                    {
                        idleManager.CancelTimer();
                    }
                }
            }
        }
        bool HandleEndAccept(IAsyncResult result)
        {
            this.channel = this.CompleteAccept(result);

            if (this.channel != null)
            {
                Fx.Assert(this.idleManager == null, "There cannot be an existing idle manager");
                this.idleManager = SessionIdleManager.CreateIfNeeded(this.channel.Binder, this.channelDispatcher.DefaultCommunicationTimeouts.ReceiveTimeout);
            }
            else
            {
                this.DoneAccepting();
                return true;
            }

            return this.AcquireThrottle();
        }