private void OnConnectionModeKnownCore(ConnectionModeReader modeReader, bool isCached)
        {
            lock (this.ThisLock)
            {
                if (this.isDisposed)
                {
                    return;
                }
                this.connectionReaders.Remove(modeReader);
            }
            bool flag = true;
            try
            {
                FramingMode connectionMode;
                try
                {
                    connectionMode = modeReader.GetConnectionMode();
                }
                catch (CommunicationException exception)
                {
                    TraceEventType exceptionEventType = modeReader.Connection.ExceptionEventType;
                    if (DiagnosticUtility.ShouldTrace(exceptionEventType))
                    {
                        DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, exceptionEventType);
                    }
                    return;
                }
                catch (TimeoutException exception2)
                {
                    if (!isCached)
                    {
                        exception2 = new TimeoutException(System.ServiceModel.SR.GetString("ChannelInitializationTimeout", new object[] { this.channelInitializationTimeout }), exception2);
                        ErrorBehavior.ThrowAndCatch(exception2);
                    }
                    TraceEventType type = modeReader.Connection.ExceptionEventType;
                    if (DiagnosticUtility.ShouldTrace(type))
                    {
                        DiagnosticUtility.ExceptionUtility.TraceHandledException(exception2, type);
                    }
                    return;
                }
                switch (connectionMode)
                {
                    case FramingMode.Singleton:
                        this.OnSingletonConnection(modeReader.Connection, modeReader.ConnectionDequeuedCallback, modeReader.StreamPosition, modeReader.BufferOffset, modeReader.BufferSize, modeReader.GetRemainingTimeout());
                        break;

                    case FramingMode.Duplex:
                        this.OnDuplexConnection(modeReader.Connection, modeReader.ConnectionDequeuedCallback, modeReader.StreamPosition, modeReader.BufferOffset, modeReader.BufferSize, modeReader.GetRemainingTimeout());
                        break;

                    default:
                    {
                        Exception innerException = new InvalidDataException(System.ServiceModel.SR.GetString("FramingModeNotSupported", new object[] { connectionMode }));
                        Exception exception4 = new ProtocolException(innerException.Message, innerException);
                        FramingEncodingString.AddFaultString(exception4, "http://schemas.microsoft.com/ws/2006/05/framing/faults/UnsupportedMode");
                        ErrorBehavior.ThrowAndCatch(exception4);
                        return;
                    }
                }
                flag = false;
            }
            catch (Exception exception5)
            {
                if (Fx.IsFatal(exception5))
                {
                    throw;
                }
                if (!System.ServiceModel.Dispatcher.ExceptionHandler.HandleTransportExceptionHelper(exception5))
                {
                    throw;
                }
            }
            finally
            {
                if (flag)
                {
                    modeReader.Dispose();
                }
            }
        }
        void OnConnectionModeKnownCore(ConnectionModeReader modeReader, bool isCached)
        {
            lock (ThisLock)
            {
                if (isDisposed)
                {
                    return;
                }

                this.connectionReaders.Remove(modeReader);
            }

            bool closeReader = true;

            try
            {
                FramingMode framingMode;
                try
                {
                    framingMode = modeReader.GetConnectionMode();
                }
                catch (CommunicationException exception)
                {
                    TraceEventType eventType = modeReader.Connection.ExceptionEventType;
                    DiagnosticUtility.TraceHandledException(exception, eventType);
                    return;
                }
                catch (TimeoutException exception)
                {
                    if (!isCached)
                    {
                        exception = new TimeoutException(SR.GetString(SR.ChannelInitializationTimeout, this.channelInitializationTimeout), exception);
                        System.ServiceModel.Dispatcher.ErrorBehavior.ThrowAndCatch(exception);
                    }

                    if (TD.ChannelInitializationTimeoutIsEnabled())
                    {
                        TD.ChannelInitializationTimeout(SR.GetString(SR.ChannelInitializationTimeout, this.channelInitializationTimeout));
                    }

                    TraceEventType eventType = modeReader.Connection.ExceptionEventType;
                    DiagnosticUtility.TraceHandledException(exception, eventType);
                    return;
                }

                switch (framingMode)
                {
                case FramingMode.Duplex:
                    OnDuplexConnection(modeReader.Connection, modeReader.ConnectionDequeuedCallback,
                                       modeReader.StreamPosition, modeReader.BufferOffset, modeReader.BufferSize,
                                       modeReader.GetRemainingTimeout());
                    break;

                case FramingMode.Singleton:
                    OnSingletonConnection(modeReader.Connection, modeReader.ConnectionDequeuedCallback,
                                          modeReader.StreamPosition, modeReader.BufferOffset, modeReader.BufferSize,
                                          modeReader.GetRemainingTimeout());
                    break;

                default:
                {
                    Exception inner = new InvalidDataException(SR.GetString(
                                                                   SR.FramingModeNotSupported, framingMode));
                    Exception exception = new ProtocolException(inner.Message, inner);
                    FramingEncodingString.AddFaultString(exception, FramingEncodingString.UnsupportedModeFault);
                    System.ServiceModel.Dispatcher.ErrorBehavior.ThrowAndCatch(exception);
                    return;
                }
                }

                closeReader = false;
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
                if (!ExceptionHandler.HandleTransportExceptionHelper(e))
                {
                    throw;
                }

                // containment -- the reader is aborted, no need for additional containment
            }
            finally
            {
                if (closeReader)
                {
                    modeReader.Dispose();
                }
            }
        }
        void OnConnectionModeKnownCore(ConnectionModeReader modeReader, bool isCached)
        {
            lock (ThisLock)
            {
                if (isDisposed)
                    return;

                this.connectionReaders.Remove(modeReader);
            }

            bool closeReader = true;
            try
            {
                FramingMode framingMode;
                try
                {
                    framingMode = modeReader.GetConnectionMode();
                }
                catch (CommunicationException exception)
                {
                    TraceEventType eventType = modeReader.Connection.ExceptionEventType;
                    DiagnosticUtility.TraceHandledException(exception, eventType);
                    return;
                }
                catch (TimeoutException exception)
                {
                    if (!isCached)
                    {
                        exception = new TimeoutException(SR.GetString(SR.ChannelInitializationTimeout, this.channelInitializationTimeout), exception);
                        System.ServiceModel.Dispatcher.ErrorBehavior.ThrowAndCatch(exception);
                    }

                    if (TD.ChannelInitializationTimeoutIsEnabled())
                    {
                        TD.ChannelInitializationTimeout(SR.GetString(SR.ChannelInitializationTimeout, this.channelInitializationTimeout));
                    }

                    TraceEventType eventType = modeReader.Connection.ExceptionEventType;
                    DiagnosticUtility.TraceHandledException(exception, eventType);
                    return;
                }

                switch (framingMode)
                {
                    case FramingMode.Duplex:
                        OnDuplexConnection(modeReader.Connection, modeReader.ConnectionDequeuedCallback,
                            modeReader.StreamPosition, modeReader.BufferOffset, modeReader.BufferSize,
                            modeReader.GetRemainingTimeout());
                        break;

                    case FramingMode.Singleton:
                        OnSingletonConnection(modeReader.Connection, modeReader.ConnectionDequeuedCallback,
                            modeReader.StreamPosition, modeReader.BufferOffset, modeReader.BufferSize,
                            modeReader.GetRemainingTimeout());
                        break;

                    default:
                        {
                            Exception inner = new InvalidDataException(SR.GetString(
                                SR.FramingModeNotSupported, framingMode));
                            Exception exception = new ProtocolException(inner.Message, inner);
                            FramingEncodingString.AddFaultString(exception, FramingEncodingString.UnsupportedModeFault);
                            System.ServiceModel.Dispatcher.ErrorBehavior.ThrowAndCatch(exception);
                            return;
                        }
                }

                closeReader = false;
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
                if (!ExceptionHandler.HandleTransportExceptionHelper(e))
                {
                    throw;
                }

                // containment -- the reader is aborted, no need for additional containment
            }
            finally
            {
                if (closeReader)
                {
                    modeReader.Dispose();
                }
            }
        }
Esempio n. 4
0
        private void OnConnectionModeKnownCore(ConnectionModeReader modeReader, bool isCached)
        {
            lock (this.ThisLock)
            {
                if (this.isDisposed)
                {
                    return;
                }
                this.connectionReaders.Remove(modeReader);
            }
            bool flag = true;

            try
            {
                FramingMode connectionMode;
                try
                {
                    connectionMode = modeReader.GetConnectionMode();
                }
                catch (CommunicationException exception)
                {
                    TraceEventType exceptionEventType = modeReader.Connection.ExceptionEventType;
                    if (DiagnosticUtility.ShouldTrace(exceptionEventType))
                    {
                        DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, exceptionEventType);
                    }
                    return;
                }
                catch (TimeoutException exception2)
                {
                    if (!isCached)
                    {
                        exception2 = new TimeoutException(System.ServiceModel.SR.GetString("ChannelInitializationTimeout", new object[] { this.channelInitializationTimeout }), exception2);
                        ErrorBehavior.ThrowAndCatch(exception2);
                    }
                    TraceEventType type = modeReader.Connection.ExceptionEventType;
                    if (DiagnosticUtility.ShouldTrace(type))
                    {
                        DiagnosticUtility.ExceptionUtility.TraceHandledException(exception2, type);
                    }
                    return;
                }
                switch (connectionMode)
                {
                case FramingMode.Singleton:
                    this.OnSingletonConnection(modeReader.Connection, modeReader.ConnectionDequeuedCallback, modeReader.StreamPosition, modeReader.BufferOffset, modeReader.BufferSize, modeReader.GetRemainingTimeout());
                    break;

                case FramingMode.Duplex:
                    this.OnDuplexConnection(modeReader.Connection, modeReader.ConnectionDequeuedCallback, modeReader.StreamPosition, modeReader.BufferOffset, modeReader.BufferSize, modeReader.GetRemainingTimeout());
                    break;

                default:
                {
                    Exception innerException = new InvalidDataException(System.ServiceModel.SR.GetString("FramingModeNotSupported", new object[] { connectionMode }));
                    Exception exception4     = new ProtocolException(innerException.Message, innerException);
                    FramingEncodingString.AddFaultString(exception4, "http://schemas.microsoft.com/ws/2006/05/framing/faults/UnsupportedMode");
                    ErrorBehavior.ThrowAndCatch(exception4);
                    return;
                }
                }
                flag = false;
            }
            catch (Exception exception5)
            {
                if (Fx.IsFatal(exception5))
                {
                    throw;
                }
                if (!System.ServiceModel.Dispatcher.ExceptionHandler.HandleTransportExceptionHelper(exception5))
                {
                    throw;
                }
            }
            finally
            {
                if (flag)
                {
                    modeReader.Dispose();
                }
            }
        }