示例#1
0
        protected override Exception OnSizeQuotaExceeded(int size)
        {
            Exception result = new InvalidDataException(string.Format(SRServiceModel.FramingContentTypeTooLong, size));

            FramingEncodingString.AddFaultString(result, FramingEncodingString.ContentTypeTooLongFault);
            return(result);
        }
示例#2
0
        protected Exception CreateException(InvalidDataException innerException, string framingFault)
        {
            Exception result = CreateException(innerException);

            FramingEncodingString.AddFaultString(result, framingFault);
            return(result);
        }
        protected Exception CreateException(InvalidDataException innerException, string framingFault)
        {
            Exception exception = this.CreateException(innerException);

            FramingEncodingString.AddFaultString(exception, framingFault);
            return(exception);
        }
        protected override Exception OnSizeQuotaExceeded(int size)
        {
            Exception exception = new InvalidDataException(System.ServiceModel.SR.GetString("FramingContentTypeTooLong", new object[] { size }));

            FramingEncodingString.AddFaultString(exception, "http://schemas.microsoft.com/ws/2006/05/framing/faults/ContentTypeTooLong");
            return(exception);
        }
示例#5
0
        protected override Exception OnSizeQuotaExceeded(int size)
        {
            Exception result = new InvalidDataException(SR.Format(SR.FramingViaTooLong, size));

            FramingEncodingString.AddFaultString(result, FramingEncodingString.ViaTooLongFault);
            return(result);
        }
 private bool ContinueReading()
 {
     while (true)
     {
         if (this.size == 0)
         {
             if (readCallback == null)
             {
                 readCallback = new WaitCallback(ConnectionModeReader.ReadCallback);
             }
             if (base.Connection.BeginRead(0, base.Connection.AsyncReadBufferSize, this.GetRemainingTimeout(), readCallback, this) == AsyncReadResult.Queued)
             {
                 return(false);
             }
             if (!this.GetReadResult())
             {
                 return(false);
             }
         }
         do
         {
             int num;
             try
             {
                 num = this.decoder.Decode(this.buffer, this.offset, this.size);
             }
             catch (CommunicationException exception)
             {
                 string str;
                 if (FramingEncodingString.TryGetFaultString(exception, out str))
                 {
                     byte[] drainBuffer = new byte[0x80];
                     InitialServerConnectionReader.SendFault(base.Connection, str, drainBuffer, this.GetRemainingTimeout(), base.MaxViaSize + base.MaxContentTypeSize);
                     base.Close(this.GetRemainingTimeout());
                 }
                 throw;
             }
             if (num > 0)
             {
                 this.offset += num;
                 this.size   -= num;
             }
             if (this.decoder.CurrentState == ServerModeDecoder.State.Done)
             {
                 return(true);
             }
         }while (this.size != 0);
     }
 }
示例#7
0
        bool ContinueReading()
        {
            for (;;)
            {
                if (size == 0)
                {
                    if (readCallback == null)
                    {
                        readCallback = new WaitCallback(ReadCallback);
                    }

                    if (Connection.BeginRead(0, Connection.AsyncReadBufferSize, GetRemainingTimeout(),
                                             readCallback, this) == AsyncCompletionResult.Queued)
                    {
                        break;
                    }
                    if (!GetReadResult()) // we're at EOF, bail
                    {
                        return(false);
                    }
                }

                for (;;)
                {
                    int bytesDecoded;
                    try
                    {
                        bytesDecoded = decoder.Decode(buffer, offset, size);
                    }
                    catch (CommunicationException e)
                    {
                        // see if we need to send back a framing fault
                        string framingFault;
                        if (FramingEncodingString.TryGetFaultString(e, out framingFault))
                        {
                            byte[] drainBuffer = new byte[128];
                            InitialServerConnectionReader.SendFault(
                                Connection, framingFault, drainBuffer, GetRemainingTimeout(),
                                MaxViaSize + MaxContentTypeSize);
                            base.Close(GetRemainingTimeout());
                        }
                        throw;
                    }

                    if (bytesDecoded > 0)
                    {
                        offset += bytesDecoded;
                        size   -= bytesDecoded;
                    }
                    if (decoder.CurrentState == ServerModeDecoder.State.Done)
                    {
                        return(true);
                    }
                    if (size == 0)
                    {
                        break;
                    }
                }
            }

            return(false);
        }
        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();
                }
            }
        }
示例#9
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();
                }
            }
        }