コード例 #1
0
        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();
                }
            }
        }