Esempio n. 1
0
 private static void Abort(IChannel channel, ChannelFactory channelFactory)
 {
     if (channel != null)
         channel.Abort();
     if (channelFactory != null)
         channelFactory.Abort();
 }
Esempio n. 2
0
        public void Abort()
        {
            IChannel channel = (IChannel)_channel;

            if (channel != null)
            {
                channel.Abort();
            }

            if (!_channelFactoryRefReleased)
            {
                lock (s_staticLock)
                {
                    if (!_channelFactoryRefReleased)
                    {
                        if (_channelFactoryRef.Release())
                        {
                            _releasedLastRef = true;
                        }

                        _channelFactoryRefReleased = true;
                    }
                }
            }

            // Abort the ChannelFactory if we released the last one. We should be able to abort it when another thread is closing it.
            if (_releasedLastRef)
            {
                _channelFactoryRef.Abort();
            }
        }
Esempio n. 3
0
 private void OnOperationFailure(SecuritySessionOperation operation, EndpointAddress target, SecurityToken currentToken, Exception e, IChannel channel)
 {
     if (channel != null)
     {
         channel.Abort();
     }
 }
Esempio n. 4
0
        public void Dispose()
        {
            if (_blnDisposed == false)
            {
                lock (_objSyncObject)
                {
                    if (_objProxy != null)
                    {
                        IChannel objChannel = _objProxy as IChannel;
                        if (objChannel != null)
                        {
                            if (objChannel.State == CommunicationState.Opened)
                            {
                                objChannel.Close();
                            }
                            else if (objChannel.State == CommunicationState.Faulted)
                            {
                                objChannel.Abort();
                                objChannel.Close();
                            }

                            objChannel.Faulted -= new EventHandler(Channel_Faulted);
                            objChannel          = null;
                        }
                    }

                    if ((_objProxy != null) && (_objProxy is IDisposable))
                    {
                        ((IDisposable)_objProxy).Dispose();
                        _objProxy = null;
                    }
                }
            }
        }
Esempio n. 5
0
 /// <summary>
 /// ExecuteOnChannel method implementation
 /// </summary>
 private void ExecuteOnSpecificChannel(string operationName, string uri, ExecuteOptions options, CodeToRunOnChannel codeBlock)
 {
     using (new SPMonitoredScope("ExecuteSpecificChannel:" + operationName))
     {
         try
         {
             string ep = FindLoadBalancerEndPoint(uri);
             if (!string.IsNullOrEmpty(ep))
             {
                 Uri      xu      = new Uri(ep);
                 IChannel channel = (IChannel)GetChannel(xu, options);
                 try
                 {
                     codeBlock((IIdentityServiceContract)channel);
                     channel.Close();
                 }
                 finally
                 {
                     if (channel.State != CommunicationState.Closed)
                     {
                         channel.Abort();
                     }
                 }
             }
         }
         finally
         {
         }
     }
 }
Esempio n. 6
0
        private bool disposedValue = false; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    // TODO: dispose managed state (managed objects).
                    if (Channel != null)
                    {
                        try
                        {
                            Channel.Close();
                        }
                        catch (Exception)
                        {
                            Channel.Abort();
                        }

                        (Channel as IDisposable).Dispose();

                        Channel = null;
                    }
                }

                // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.
                // TODO: set large fields to null.

                disposedValue = true;
            }
        }
        public void Abort()
        {
            IChannel channel = (IChannel)this.channel;

            if (channel != null)
            {
                channel.Abort();
            }
            if (!this.channelFactoryRefReleased)
            {
                lock (ClientBase <TChannel> .staticLock)
                {
                    if (!this.channelFactoryRefReleased)
                    {
                        if (this.channelFactoryRef.Release())
                        {
                            this.releasedLastRef = true;
                        }
                        this.channelFactoryRefReleased = true;
                    }
                }
            }
            if (this.releasedLastRef)
            {
                this.channelFactoryRef.Abort();
            }
        }
Esempio n. 8
0
        async Task CloseChannelAsync(IChannel channel, CancellationToken token)
        {
            try
            {
                if (channel.State != CommunicationState.Closing && channel.State != CommunicationState.Closed)
                {
                    CloseChannelState state = new CloseChannelState(this, channel);
                    if (channel is ISessionChannel <IDuplexSession> )
                    {
                        IDuplexSession duplexSession = ((ISessionChannel <IDuplexSession>)channel).Session;
                        await duplexSession.CloseOutputSessionAsync(token);
                    }
                    else
                    {
                        await channel.CloseAsync(token);
                    }
                }
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
                HandleError(e);

                if (channel is ISessionChannel <IDuplexSession> )
                {
                    channel.Abort();
                }
            }
        }
Esempio n. 9
0
 static void Abort(IChannel channel, ChannelFactory cf)
 {
     if (channel != null)
         channel.Abort();
     if (cf != null)
         cf.Abort();
 }
Esempio n. 10
0
 protected override void OnAbort()
 {
     channel.Abort();
     if (factory != null)             // ... is it valid?
     {
         factory.Abort();
     }
 }
Esempio n. 11
0
 protected override void OnAbort()
 {
     channel.Abort();
     if (factory != null)
     {
         factory.Abort();
     }
 }
 void OnOperationFailure(SecuritySessionOperation operation, EndpointAddress target, SecurityToken currentToken, Exception e, IChannel channel)
 {
     SecurityTraceRecordHelper.TraceSecuritySessionOperationFailure(operation, target, currentToken, e);
     if (channel != null)
     {
         channel.Abort();
     }
 }
Esempio n. 13
0
        /// <summary>
        /// ExecuteOnChannel method implementation
        /// </summary>
        private void ExecuteOnChannel(string operationName, ExecuteOptions options, CodeToRunOnChannel codeBlock)
        {
            using (new SPMonitoredScope("ExecuteOnChannel:" + operationName))
            {
                bool   mustexit     = false;
                string firstaddress = "";
                do
                {
                    SPServiceLoadBalancerContext loadBalancerContext = m_LoadBalancer.BeginOperation();
                    try
                    {
                        if (firstaddress.Equals(loadBalancerContext.EndpointAddress.ToString()))
                        {
                            mustexit = true;
                        }
                        if (!mustexit)
                        {
                            if ((loadBalancerContext.Status == SPServiceLoadBalancerStatus.Succeeded))
                            {
                                if (string.IsNullOrEmpty(firstaddress))
                                {
                                    firstaddress = loadBalancerContext.EndpointAddress.ToString();
                                }

                                IChannel channel = (IChannel)GetChannel(loadBalancerContext.EndpointAddress, options);
                                try
                                {
                                    codeBlock((IIdentityServiceContract)channel);
                                    channel.Close();
                                    mustexit = true;
                                }
                                catch (TimeoutException)
                                {
                                    loadBalancerContext.Status = SPServiceLoadBalancerStatus.Failed;
                                }
                                catch (EndpointNotFoundException)
                                {
                                    loadBalancerContext.Status = SPServiceLoadBalancerStatus.Failed;
                                }
                                finally
                                {
                                    if (channel.State != CommunicationState.Closed)
                                    {
                                        channel.Abort();
                                    }
                                }
                            }
                        }
                    }
                    finally
                    {
                        loadBalancerContext.EndOperation();
                    }
                }while (!mustexit);
            }
        }
Esempio n. 14
0
        public void Abort()
        {
            IChannel channel = (IChannel)_channel;

            if (channel != null)
            {
                channel.Abort();
            }
            ChannelFactory.Abort();
        }
Esempio n. 15
0
 static void Abort(IChannel channel, ChannelFactory cf)
 {
     if (channel != null)
     {
         channel.Abort();
     }
     if (cf != null)
     {
         cf.Abort();
     }
 }
Esempio n. 16
0
 private static void Abort(IChannel channel, ChannelFactory channelFactory)
 {
     if (channel != null)
     {
         channel.Abort();
     }
     if (channelFactory != null)
     {
         channelFactory.Abort();
     }
 }
Esempio n. 17
0
 private void Cleanup(IChannel rstChannel, T negotiationState)
 {
     if (negotiationState != null)
     {
         negotiationState.Dispose();
     }
     if (rstChannel != null)
     {
         rstChannel.Abort();
     }
 }
 protected override void OnAbort()
 {
     if (security_initiator != null)
     {
         security_initiator.Release();
     }
     else
     {
         security_recipient.Release();
     }
     channel.Abort();
 }
Esempio n. 19
0
        /// <summary>
        /// Closes the given channel.
        /// </summary>
        /// <param name="athenaChannel">The channel to be close.</param>
        private void CloseChannel(IAthenaWcfService athenaChannel)
        {
            IChannel ch = athenaChannel as IChannel;

            try
            {
                ch.Close(m_CommunicationTimeout);
            }
            catch (TimeoutException)
            {
                ch.Abort();
            }
        }
Esempio n. 20
0
 public void Abort()
 {
     lock (_objSyncObject)
     {
         if (_objProxy != null)
         {
             IChannel objChannel = _objProxy as IChannel;
             if (objChannel != null)
             {
                 objChannel.Abort();
             }
         }
     }
 }
Esempio n. 21
0
        private void Proxy_Faulted(object sender, EventArgs e)
        {
            //EFaulted();
            workTimer.Stop();

            IChannel channel = sender as IChannel;

            if (channel != null)
            {
                channel.Abort();
                channel.Close();
            }

            AbortProxy(true);
        }
    void ICommunicationObject_Faulted(object sender, System.EventArgs e)
    {
        DefaultLogger.DUPLEXLogger.Error("context_Faulted");
        this.OnInstanceContextFaulted(e);
        if (_Timer != null)
        {
            _Timer.Dispose();
        }
        IChannel channel = sender as IChannel;

        if (channel != null)
        {
            channel.Abort();
            channel.Close();
        }
        DoWorkRoutine(cToken);
    }
Esempio n. 23
0
        public void Dispose()
        {
            IChannel connection = null;

            try
            {
                connection = (IChannel)Channel;
                connection.Close();
            }
            catch (Exception)
            {
                if (connection != null)
                {
                    connection.Abort();
                }
            }
        }
        public void AddIncomingChannel(IChannel channel)
        {
            bool added = false;

            lock (ThisLock)
            {
                if (State == LifetimeState.Opened)
                {
                    if (_firstIncomingChannel == null)
                    {
                        if (_incomingChannels == null)
                        {
                            _firstIncomingChannel = channel;
                            ChannelAdded(channel);
                        }
                        else
                        {
                            if (_incomingChannels.Contains(channel))
                            {
                                return;
                            }

                            _incomingChannels.Add(channel);
                        }
                    }
                    else
                    {
                        EnsureIncomingChannelCollection();
                        if (_incomingChannels.Contains(channel))
                        {
                            return;
                        }

                        _incomingChannels.Add(channel);
                    }
                    added = true;
                }
            }

            if (!added)
            {
                channel.Abort();
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ObjectDisposedException(GetType().ToString()));
            }
        }
Esempio n. 25
0
        public void AddIncomingChannel(IChannel channel)
        {
            bool flag = false;

            lock (base.ThisLock)
            {
                if (base.State == LifetimeState.Opened)
                {
                    if (this.firstIncomingChannel == null)
                    {
                        if (this.incomingChannels == null)
                        {
                            this.firstIncomingChannel = channel;
                            this.ChannelAdded(channel);
                        }
                        else
                        {
                            if (this.incomingChannels.Contains(channel))
                            {
                                return;
                            }
                            this.incomingChannels.Add(channel);
                        }
                    }
                    else
                    {
                        this.EnsureIncomingChannelCollection();
                        if (this.incomingChannels.Contains(channel))
                        {
                            return;
                        }
                        this.incomingChannels.Add(channel);
                    }
                    flag = true;
                }
            }
            if (!flag)
            {
                channel.Abort();
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ObjectDisposedException(base.GetType().ToString()));
            }
        }
        protected override void OnAbort()
        {
            IChannel channel = null;

            lock (ThisLock)
            {
                channel = (channelsList.Count > 0) ? channelsList[channelsList.Count - 1] : null;
            }

            while (channel != null)
            {
                channel.Abort();

                lock (ThisLock)
                {
                    channelsList.Remove(channel);
                    channel = (channelsList.Count > 0) ? channelsList[channelsList.Count - 1] : null;
                }
            }
        }
Esempio n. 27
0
 private static void CloseChannel(IChannel channel)
 {
     try
     {
         if (channel != null)
         {
             if (channel.State == CommunicationState.Faulted)
             {
                 channel.Abort();
             }
             else
             {
                 channel.Close();
             }
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Something blew up when closing a channel: {0}", ex.Message);
     }
 }
Esempio n. 28
0
        /// <summary>
        /// Fecha um wcf channel associado a uma instancia de servico
        /// </summary>
        /// <param name="servico">instancia de um objeto criado anteriormente com Ativador.Get()</param>
        public static void AbortChannel(object servico)
        {
            try
            {
                if (servico == null)
                {
                    logger.Error("Erro em Ativador.AbortChannel(): Parametro nao pode ser nulo");
                    return;
                }

                IDuplexChannel channel2 = servico as IDuplexChannel;
                if (channel2 != null)
                {
                    logger.Info("Abort duplex channel for: " + servico.ToString());
                    channel2.Close();
                }
                else
                {
                    IChannel channel = servico as IChannel;
                    if (channel != null)
                    {
                        logger.Info("Abort channel for: " + servico.ToString());
                        try
                        {
                            channel.Close();
                        }
                        catch (Exception ex)
                        {
                            logger.Error("Erro em Ativador.AbortChannel()" + ex.Message, ex);
                            logger.Error("Trying really abort the channel");
                            channel.Abort();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error("Erro em Ativador.AbortChannel()" + ex.Message, ex);
            }
        }
Esempio n. 29
0
        private void CloseChannel(IChannel channel, TimeSpan timeout)
        {
            try
            {
                if (channel.State != CommunicationState.Closing && channel.State != CommunicationState.Closed)
                {
                    CloseChannelState state = new CloseChannelState(this, channel);
                    if (channel is ISessionChannel <IDuplexSession> )
                    {
                        IDuplexSession duplexSession = ((ISessionChannel <IDuplexSession>)channel).Session;
                        IAsyncResult   result        = duplexSession.BeginCloseOutputSession(timeout, Fx.ThunkCallback(new AsyncCallback(CloseOutputSessionCallback)), state);
                        if (result.CompletedSynchronously)
                        {
                            duplexSession.EndCloseOutputSession(result);
                        }
                    }
                    else
                    {
                        IAsyncResult result = channel.BeginClose(timeout, Fx.ThunkCallback(new AsyncCallback(CloseChannelCallback)), state);
                        if (result.CompletedSynchronously)
                        {
                            channel.EndClose(result);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
                this.HandleError(e);

                if (channel is ISessionChannel <IDuplexSession> )
                {
                    channel.Abort();
                }
            }
        }
Esempio n. 30
0
        protected override void OnAbort()
        {
            IChannel item = null;

            lock (base.ThisLock)
            {
                item = (this.channelsList.Count > 0) ? this.channelsList[this.channelsList.Count - 1] : null;
                goto Label_00A5;
            }
Label_0049:
            item.Abort();
            lock (base.ThisLock)
            {
                this.channelsList.Remove(item);
                item = (this.channelsList.Count > 0) ? this.channelsList[this.channelsList.Count - 1] : null;
            }
Label_00A5:
            if (item != null)
            {
                goto Label_0049;
            }
        }
Esempio n. 31
0
        private void EnsureChannelIsAvailable()
        {
            if (ShouldCreateChannel)
            {
                lock (m_Lock)
                {
                    if (ShouldCreateChannel)
                    {
                        if (m_Channel != null)
                        {
                            // The channel is probably faulted so terminate it.
                            m_Diagnostics.Log(
                                LevelToLog.Info,
                                CommunicationConstants.DefaultLogTextPrefix,
                                string.Format(
                                    CultureInfo.InvariantCulture,
                                    "Data channel for endpoint at {0} has faulted. Aborting channel.",
                                    m_Factory.Endpoint.Address.Uri));
                            m_Channel.Abort();
                            m_Service.Faulted -= HandleOnChannelFaulting;
                        }

                        m_Diagnostics.Log(
                            LevelToLog.Info,
                            CommunicationConstants.DefaultLogTextPrefix,
                            string.Format(
                                CultureInfo.InvariantCulture,
                                "Creating data channel for endpoint at {0}.",
                                m_Factory.Endpoint.Address.Uri));

                        m_WasFaulted       = false;
                        m_Service          = m_Factory.CreateChannel();
                        m_Channel          = m_Service;
                        m_Service.Faulted += HandleOnChannelFaulting;
                    }
                }
            }
        }
        private void ExecuteOnChannel(string operationName, CodeToRunOnChannel codeBlock)
        {
            SPServiceLoadBalancerContext loadBalancerContext = _loadBalancer.BeginOperation();

            try
            {
                // get a channel to the service app endpoint
                IChannel channel = (IChannel)GetChannel(loadBalancerContext.EndpointAddress);
                try
                {
                    // execute the code block
                    codeBlock((IDayNamerContract)channel);
                    channel.Close();
                }
                catch (TimeoutException)
                {
                    loadBalancerContext.Status = SPServiceLoadBalancerStatus.Failed;
                    throw;
                }
                catch (EndpointNotFoundException)
                {
                    loadBalancerContext.Status = SPServiceLoadBalancerStatus.Failed;
                    throw;
                }
                finally
                {
                    if (channel.State != CommunicationState.Closed)
                    {
                        channel.Abort();
                    }
                }
            }
            finally
            {
                loadBalancerContext.EndOperation();
            }
        }
 private void CloseChannel(IChannel channel, TimeSpan timeout)
 {
     try
     {
         if ((channel.State != CommunicationState.Closing) && (channel.State != CommunicationState.Closed))
         {
             CloseChannelState state = new CloseChannelState(this, channel);
             if (channel is ISessionChannel<IDuplexSession>)
             {
                 IDuplexSession session = ((ISessionChannel<IDuplexSession>) channel).Session;
                 IAsyncResult result = session.BeginCloseOutputSession(timeout, Fx.ThunkCallback(new AsyncCallback(ListenerHandler.CloseOutputSessionCallback)), state);
                 if (result.CompletedSynchronously)
                 {
                     session.EndCloseOutputSession(result);
                 }
             }
             else
             {
                 IAsyncResult result2 = channel.BeginClose(timeout, Fx.ThunkCallback(new AsyncCallback(ListenerHandler.CloseChannelCallback)), state);
                 if (result2.CompletedSynchronously)
                 {
                     channel.EndClose(result2);
                 }
             }
         }
     }
     catch (Exception exception)
     {
         if (Fx.IsFatal(exception))
         {
             throw;
         }
         this.HandleError(exception);
         if (channel is ISessionChannel<IDuplexSession>)
         {
             channel.Abort();
         }
     }
 }