protected override Message DecodeMessage(byte[] buffer, ref int offset, ref int size, ref bool isAtEof, TimeSpan timeout)
                {
                    Message message;
                    ServiceModelActivity serviceModelActivity;

                    while (!isAtEof && size > 0)
                    {
                        int num = this.decoder.Decode(buffer, offset, size);
                        if (num > 0)
                        {
                            if (base.EnvelopeBuffer != null)
                            {
                                if (!object.ReferenceEquals(buffer, base.EnvelopeBuffer))
                                {
                                    Buffer.BlockCopy(buffer, offset, base.EnvelopeBuffer, base.EnvelopeOffset, num);
                                }
                                Microsoft.ServiceBus.Channels.ServerSessionPreambleConnectionReader.ServerFramingDuplexSessionChannel.ServerSessionConnectionReader envelopeOffset = this;
                                envelopeOffset.EnvelopeOffset = envelopeOffset.EnvelopeOffset + num;
                            }
                            offset = offset + num;
                            size   = size - num;
                        }
                        switch (this.decoder.CurrentState)
                        {
                        case Microsoft.ServiceBus.Channels.ServerSessionDecoder.State.EnvelopeStart:
                        {
                            int envelopeSize = this.decoder.EnvelopeSize;
                            if (envelopeSize > this.maxBufferSize)
                            {
                                base.SendFault("http://schemas.microsoft.com/ws/2006/05/framing/faults/MaxMessageSizeExceededFault", timeout);
                                throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperError(Microsoft.ServiceBus.Channels.MaxMessageSizeStream.CreateMaxReceivedMessageSizeExceededException((long)this.maxBufferSize));
                            }
                            base.EnvelopeBuffer = this.bufferManager.TakeBuffer(envelopeSize);
                            base.EnvelopeOffset = 0;
                            base.EnvelopeSize   = envelopeSize;
                            continue;
                        }

                        case Microsoft.ServiceBus.Channels.ServerSessionDecoder.State.EnvelopeEnd:
                        {
                            if (base.EnvelopeBuffer == null)
                            {
                                continue;
                            }
                            if (Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ShouldUseActivity)
                            {
                                serviceModelActivity = ServiceModelActivity.CreateBoundedActivity(true);
                            }
                            else
                            {
                                serviceModelActivity = null;
                            }
                            using (serviceModelActivity)
                            {
                                Message message1 = null;
                                try
                                {
                                    message1 = this.messageEncoder.ReadMessage(new ArraySegment <byte>(base.EnvelopeBuffer, 0, base.EnvelopeSize), this.bufferManager, this.contentType);
                                }
                                catch (XmlException xmlException1)
                                {
                                    XmlException xmlException = xmlException1;
                                    throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ProtocolException(Microsoft.ServiceBus.SR.GetString(Resources.MessageXmlProtocolError, new object[0]), xmlException));
                                }
                                base.EnvelopeBuffer = null;
                                message             = message1;
                            }
                            return(message);
                        }

                        case Microsoft.ServiceBus.Channels.ServerSessionDecoder.State.End:
                        {
                            isAtEof = true;
                            continue;
                        }

                        default:
                        {
                            continue;
                        }
                        }
                    }
                    return(null);
                }
 private void SetupSessionReader()
 {
     this.sessionReader = new Microsoft.ServiceBus.Channels.ServerSessionPreambleConnectionReader.ServerFramingDuplexSessionChannel.ServerSessionConnectionReader(this);
     base.SetMessageSource(this.sessionReader);
 }