public ListenerSessionConnectionReader(IConnection connection,
     Action connectionDequeuedCallback, TransportType transportType, 
     long streamPosition, int offset, int size, 
     ConnectionClosedCallback closedCallback, ViaDecodedCallback viaDecodedCallback)
     : base(connection, connectionDequeuedCallback, transportType, offset, size, closedCallback, viaDecodedCallback)
 {
     this.decoder = new ServerSessionDecoder(streamPosition, ListenerConstants.MaxUriSize, ListenerConstants.SharedMaxContentTypeSize);
 }
 public ServerSessionConnectionReader(ServerSessionPreambleConnectionReader.ServerFramingDuplexSessionChannel channel) : base(channel.Connection, channel.rawConnection, channel.offset, channel.size, channel.RemoteSecurity)
 {
     this.decoder = channel.decoder;
     this.contentType = this.decoder.ContentType;
     this.maxBufferSize = channel.channelListener.MaxBufferSize;
     this.bufferManager = channel.channelListener.BufferManager;
     this.messageEncoder = channel.MessageEncoder;
     this.rawConnection = channel.rawConnection;
 }
 public ServerSessionPreambleConnectionReader(IConnection connection, Action connectionDequeuedCallback, long streamPosition, int offset, int size, TransportSettingsCallback transportSettingsCallback, ConnectionClosedCallback closedCallback, ServerSessionPreambleCallback callback) : base(connection, closedCallback)
 {
     this.rawConnection = connection;
     this.decoder = new ServerSessionDecoder(streamPosition, base.MaxViaSize, base.MaxContentTypeSize);
     this.offset = offset;
     this.size = size;
     this.transportSettingsCallback = transportSettingsCallback;
     this.callback = callback;
     base.ConnectionDequeuedCallback = connectionDequeuedCallback;
 }
 public ServerFramingDuplexSessionChannel(ConnectionOrientedTransportChannelListener channelListener, ServerSessionPreambleConnectionReader preambleReader, EndpointAddress localAddress, bool exposeConnectionProperty, ConnectionDemuxer connectionDemuxer) : base(channelListener, localAddress, preambleReader.Via, exposeConnectionProperty)
 {
     this.channelListener = channelListener;
     this.connectionDemuxer = connectionDemuxer;
     base.Connection = preambleReader.Connection;
     this.decoder = preambleReader.Decoder;
     this.connectionBuffer = preambleReader.connectionBuffer;
     this.offset = preambleReader.BufferOffset;
     this.size = preambleReader.BufferSize;
     this.rawConnection = preambleReader.RawConnection;
     StreamUpgradeProvider upgrade = channelListener.Upgrade;
     if (upgrade != null)
     {
         this.channelBindingProvider = upgrade.GetProperty<IStreamUpgradeChannelBindingProvider>();
         this.upgradeAcceptor = upgrade.CreateUpgradeAcceptor();
     }
 }
 internal static IInputSessionChannel DecodeTransportSessiongram(MsmqInputSessionChannelListener listener, MsmqInputMessage msmqMessage, MsmqMessageProperty messageProperty, MsmqReceiveContextLockManager receiveContextManager)
 {
     using (MsmqDiagnostics.BoundReceiveBytesOperation())
     {
         int num4;
         long num1 = msmqMessage.LookupId.Value;
         int size = msmqMessage.BodyLength.Value;
         int offset = 0;
         byte[] incoming = msmqMessage.Body.Buffer;
         MsmqReceiveHelper msmqReceiveHelper = listener.MsmqReceiveHelper;
         ServerModeDecoder modeDecoder = new ServerModeDecoder();
         try
         {
             ReadServerMode(listener, modeDecoder, incoming, messageProperty.LookupId, ref offset, ref size);
         }
         catch (ProtocolException exception)
         {
             msmqReceiveHelper.FinalDisposition(messageProperty);
             throw listener.NormalizePoisonException(messageProperty.LookupId, exception);
         }
         if (modeDecoder.Mode != FramingMode.Simplex)
         {
             msmqReceiveHelper.FinalDisposition(messageProperty);
             throw listener.NormalizePoisonException(messageProperty.LookupId, new ProtocolException(System.ServiceModel.SR.GetString("MsmqBadFrame")));
         }
         MsmqInputSessionChannel channel = null;
         ServerSessionDecoder decoder2 = new ServerSessionDecoder(0L, 0x800, 0x100);
         try
         {
             do
             {
                 if (size <= 0)
                 {
                     throw listener.NormalizePoisonException(messageProperty.LookupId, decoder2.CreatePrematureEOFException());
                 }
                 int num3 = decoder2.Decode(incoming, offset, size);
                 offset += num3;
                 size -= num3;
             }
             while (ServerSessionDecoder.State.EnvelopeStart != decoder2.CurrentState);
         }
         catch (ProtocolException exception2)
         {
             msmqReceiveHelper.FinalDisposition(messageProperty);
             throw listener.NormalizePoisonException(messageProperty.LookupId, exception2);
         }
         MessageEncoder encoder = listener.MessageEncoderFactory.CreateSessionEncoder();
         if (!encoder.IsContentTypeSupported(decoder2.ContentType))
         {
             msmqReceiveHelper.FinalDisposition(messageProperty);
             throw listener.NormalizePoisonException(messageProperty.LookupId, new ProtocolException(System.ServiceModel.SR.GetString("MsmqBadContentType")));
         }
         ReceiveContext sessiongramReceiveContext = null;
         if (msmqReceiveHelper.MsmqReceiveParameters.ReceiveContextSettings.Enabled)
         {
             sessiongramReceiveContext = receiveContextManager.CreateMsmqReceiveContext(msmqMessage.LookupId.Value);
         }
         channel = new MsmqInputSessionChannel(listener, Transaction.Current, sessiongramReceiveContext);
         Message item = DecodeSessiongramMessage(listener, channel, encoder, messageProperty, incoming, offset, decoder2.EnvelopeSize);
         SecurityMessageProperty property = null;
         try
         {
             property = listener.ValidateSecurity(msmqMessage);
         }
         catch (Exception exception3)
         {
             if (Fx.IsFatal(exception3))
             {
                 throw;
             }
             channel.FaultChannel();
             msmqReceiveHelper.FinalDisposition(messageProperty);
             throw listener.NormalizePoisonException(messageProperty.LookupId, exception3);
         }
         if (property != null)
         {
             item.Properties.Security = property;
         }
         item.Properties["MsmqMessageProperty"] = messageProperty;
         channel.EnqueueAndDispatch(item);
         listener.RaiseMessageReceived();
     Label_01F6:
         try
         {
             if (size <= 0)
             {
                 channel.FaultChannel();
                 msmqReceiveHelper.FinalDisposition(messageProperty);
                 throw listener.NormalizePoisonException(messageProperty.LookupId, decoder2.CreatePrematureEOFException());
             }
             num4 = decoder2.Decode(incoming, offset, size);
         }
         catch (ProtocolException exception4)
         {
             channel.FaultChannel();
             msmqReceiveHelper.FinalDisposition(messageProperty);
             throw listener.NormalizePoisonException(messageProperty.LookupId, exception4);
         }
         offset += num4;
         size -= num4;
         if (ServerSessionDecoder.State.End != decoder2.CurrentState)
         {
             if (ServerSessionDecoder.State.EnvelopeStart == decoder2.CurrentState)
             {
                 item = DecodeSessiongramMessage(listener, channel, encoder, messageProperty, incoming, offset, decoder2.EnvelopeSize);
                 if (property != null)
                 {
                     item.Properties.Security = (SecurityMessageProperty) property.CreateCopy();
                 }
                 item.Properties["MsmqMessageProperty"] = messageProperty;
                 channel.EnqueueAndDispatch(item);
                 listener.RaiseMessageReceived();
             }
             goto Label_01F6;
         }
         channel.Shutdown();
         MsmqDiagnostics.SessiongramReceived(channel.Session.Id, msmqMessage.MessageId, channel.InternalPendingItems);
         return channel;
     }
 }
        internal static IInputSessionChannel DecodeTransportSessiongram(
            MsmqInputSessionChannelListener listener,
            MsmqInputMessage msmqMessage,
            MsmqMessageProperty messageProperty,
            MsmqReceiveContextLockManager receiveContextManager)
        {
            using (MsmqDiagnostics.BoundReceiveBytesOperation())
            {
                long lookupId = msmqMessage.LookupId.Value;

                int size = msmqMessage.BodyLength.Value;
                int offset = 0;
                byte[] incoming = msmqMessage.Body.Buffer;
                MsmqReceiveHelper receiver = listener.MsmqReceiveHelper;

                ServerModeDecoder modeDecoder = new ServerModeDecoder();
                try
                {
                    ReadServerMode(listener, modeDecoder, incoming, messageProperty.LookupId, ref offset, ref size);
                }
                catch (ProtocolException ex)
                {
                    receiver.FinalDisposition(messageProperty);
                    throw listener.NormalizePoisonException(messageProperty.LookupId, ex);
                }

                if (modeDecoder.Mode != FramingMode.Simplex)
                {
                    receiver.FinalDisposition(messageProperty);
                    throw listener.NormalizePoisonException(messageProperty.LookupId, new ProtocolException(SR.GetString(SR.MsmqBadFrame)));
                }

                MsmqInputSessionChannel channel = null;
                ServerSessionDecoder sessionDecoder = new ServerSessionDecoder(0, defaultMaxViaSize, defaultMaxContentTypeSize);

                try
                {
                    for (;;)
                    {
                        if (size <= 0)
                        {
                            throw listener.NormalizePoisonException(messageProperty.LookupId, sessionDecoder.CreatePrematureEOFException());
                        }

                        int decoded = sessionDecoder.Decode(incoming, offset, size);
                        offset += decoded;
                        size -= decoded;
                        if (ServerSessionDecoder.State.EnvelopeStart == sessionDecoder.CurrentState)
                            break;
                    }
                }
                catch (ProtocolException ex)
                {
                    receiver.FinalDisposition(messageProperty);
                    throw listener.NormalizePoisonException(messageProperty.LookupId, ex);
                }

                MessageEncoder encoder = listener.MessageEncoderFactory.CreateSessionEncoder();

                if (!encoder.IsContentTypeSupported(sessionDecoder.ContentType))
                {
                    receiver.FinalDisposition(messageProperty);
                    throw listener.NormalizePoisonException(messageProperty.LookupId, new ProtocolException(SR.GetString(SR.MsmqBadContentType)));
                }

                ReceiveContext receiveContext = null;

                // tack on the receive context property depending on the receive mode
                if (receiver.MsmqReceiveParameters.ReceiveContextSettings.Enabled)
                {
                    receiveContext = receiveContextManager.CreateMsmqReceiveContext(msmqMessage.LookupId.Value);
                }

                channel = new MsmqInputSessionChannel(listener, Transaction.Current, receiveContext);

                Message message = DecodeSessiongramMessage(listener, channel, encoder, messageProperty, incoming, offset, sessionDecoder.EnvelopeSize);

                SecurityMessageProperty securityProperty = null;
                try
                {
                    securityProperty = listener.ValidateSecurity(msmqMessage);
                }
                catch (Exception ex)
                {
                    if (Fx.IsFatal(ex))
                        throw;
                    channel.FaultChannel();
                    receiver.FinalDisposition(messageProperty);
                    throw listener.NormalizePoisonException(messageProperty.LookupId, ex);
                }

                if (null != securityProperty)
                    message.Properties.Security = securityProperty;

                message.Properties[MsmqMessageProperty.Name] = messageProperty;
                channel.EnqueueAndDispatch(message);
                listener.RaiseMessageReceived();

                for (;;)
                {
                    int decoded;
                    try
                    {
                        if (size <= 0)
                        {
                            channel.FaultChannel();
                            receiver.FinalDisposition(messageProperty);
                            throw listener.NormalizePoisonException(messageProperty.LookupId, sessionDecoder.CreatePrematureEOFException());
                        }

                        decoded = sessionDecoder.Decode(incoming, offset, size);
                    }
                    catch (ProtocolException ex)
                    {
                        channel.FaultChannel();
                        receiver.FinalDisposition(messageProperty);
                        throw listener.NormalizePoisonException(messageProperty.LookupId, ex);
                    }
                    offset += decoded;
                    size -= decoded;
                    if (ServerSessionDecoder.State.End == sessionDecoder.CurrentState)
                        break;
                    if (ServerSessionDecoder.State.EnvelopeStart == sessionDecoder.CurrentState)
                    {
                        message = DecodeSessiongramMessage(listener, channel, encoder, messageProperty, incoming, offset, sessionDecoder.EnvelopeSize);
                        if (null != securityProperty)
                        {
                            message.Properties.Security = (SecurityMessageProperty)securityProperty.CreateCopy();
                        }
                        message.Properties[MsmqMessageProperty.Name] = messageProperty;
                        channel.EnqueueAndDispatch(message);
                        listener.RaiseMessageReceived();
                    }
                }

                channel.Shutdown();
                MsmqDiagnostics.SessiongramReceived(channel.Session.Id, msmqMessage.MessageId, channel.InternalPendingItems);

                return channel;
            }
        }
예제 #7
0
        internal static IInputSessionChannel DecodeTransportSessiongram(
            MsmqInputSessionChannelListener listener,
            MsmqInputMessage msmqMessage,
            MsmqMessageProperty messageProperty,
            MsmqReceiveContextLockManager receiveContextManager)
        {
            using (MsmqDiagnostics.BoundReceiveBytesOperation())
            {
                long lookupId = msmqMessage.LookupId.Value;

                int               size     = msmqMessage.BodyLength.Value;
                int               offset   = 0;
                byte[]            incoming = msmqMessage.Body.Buffer;
                MsmqReceiveHelper receiver = listener.MsmqReceiveHelper;

                ServerModeDecoder modeDecoder = new ServerModeDecoder();
                try
                {
                    ReadServerMode(listener, modeDecoder, incoming, messageProperty.LookupId, ref offset, ref size);
                }
                catch (ProtocolException ex)
                {
                    receiver.FinalDisposition(messageProperty);
                    throw listener.NormalizePoisonException(messageProperty.LookupId, ex);
                }

                if (modeDecoder.Mode != FramingMode.Simplex)
                {
                    receiver.FinalDisposition(messageProperty);
                    throw listener.NormalizePoisonException(messageProperty.LookupId, new ProtocolException(SR.GetString(SR.MsmqBadFrame)));
                }

                MsmqInputSessionChannel channel        = null;
                ServerSessionDecoder    sessionDecoder = new ServerSessionDecoder(0, defaultMaxViaSize, defaultMaxContentTypeSize);

                try
                {
                    for (;;)
                    {
                        if (size <= 0)
                        {
                            throw listener.NormalizePoisonException(messageProperty.LookupId, sessionDecoder.CreatePrematureEOFException());
                        }

                        int decoded = sessionDecoder.Decode(incoming, offset, size);
                        offset += decoded;
                        size   -= decoded;
                        if (ServerSessionDecoder.State.EnvelopeStart == sessionDecoder.CurrentState)
                        {
                            break;
                        }
                    }
                }
                catch (ProtocolException ex)
                {
                    receiver.FinalDisposition(messageProperty);
                    throw listener.NormalizePoisonException(messageProperty.LookupId, ex);
                }

                MessageEncoder encoder = listener.MessageEncoderFactory.CreateSessionEncoder();

                if (!encoder.IsContentTypeSupported(sessionDecoder.ContentType))
                {
                    receiver.FinalDisposition(messageProperty);
                    throw listener.NormalizePoisonException(messageProperty.LookupId, new ProtocolException(SR.GetString(SR.MsmqBadContentType)));
                }

                ReceiveContext receiveContext = null;

                // tack on the receive context property depending on the receive mode
                if (receiver.MsmqReceiveParameters.ReceiveContextSettings.Enabled)
                {
                    receiveContext = receiveContextManager.CreateMsmqReceiveContext(msmqMessage.LookupId.Value);
                }

                channel = new MsmqInputSessionChannel(listener, Transaction.Current, receiveContext);

                Message message = DecodeSessiongramMessage(listener, channel, encoder, messageProperty, incoming, offset, sessionDecoder.EnvelopeSize);

                SecurityMessageProperty securityProperty = null;
                try
                {
                    securityProperty = listener.ValidateSecurity(msmqMessage);
                }
                catch (Exception ex)
                {
                    if (Fx.IsFatal(ex))
                    {
                        throw;
                    }
                    channel.FaultChannel();
                    receiver.FinalDisposition(messageProperty);
                    throw listener.NormalizePoisonException(messageProperty.LookupId, ex);
                }

                if (null != securityProperty)
                {
                    message.Properties.Security = securityProperty;
                }

                message.Properties[MsmqMessageProperty.Name] = messageProperty;
                channel.EnqueueAndDispatch(message);
                listener.RaiseMessageReceived();

                for (;;)
                {
                    int decoded;
                    try
                    {
                        if (size <= 0)
                        {
                            channel.FaultChannel();
                            receiver.FinalDisposition(messageProperty);
                            throw listener.NormalizePoisonException(messageProperty.LookupId, sessionDecoder.CreatePrematureEOFException());
                        }

                        decoded = sessionDecoder.Decode(incoming, offset, size);
                    }
                    catch (ProtocolException ex)
                    {
                        channel.FaultChannel();
                        receiver.FinalDisposition(messageProperty);
                        throw listener.NormalizePoisonException(messageProperty.LookupId, ex);
                    }
                    offset += decoded;
                    size   -= decoded;
                    if (ServerSessionDecoder.State.End == sessionDecoder.CurrentState)
                    {
                        break;
                    }
                    if (ServerSessionDecoder.State.EnvelopeStart == sessionDecoder.CurrentState)
                    {
                        message = DecodeSessiongramMessage(listener, channel, encoder, messageProperty, incoming, offset, sessionDecoder.EnvelopeSize);
                        if (null != securityProperty)
                        {
                            message.Properties.Security = (SecurityMessageProperty)securityProperty.CreateCopy();
                        }
                        message.Properties[MsmqMessageProperty.Name] = messageProperty;
                        channel.EnqueueAndDispatch(message);
                        listener.RaiseMessageReceived();
                    }
                }

                channel.Shutdown();
                MsmqDiagnostics.SessiongramReceived(channel.Session.Id, msmqMessage.MessageId, channel.InternalPendingItems);

                return(channel);
            }
        }
        internal static IInputSessionChannel DecodeTransportSessiongram(MsmqInputSessionChannelListener listener, MsmqInputMessage msmqMessage, MsmqMessageProperty messageProperty, MsmqReceiveContextLockManager receiveContextManager)
        {
            using (MsmqDiagnostics.BoundReceiveBytesOperation())
            {
                int               num4;
                long              num1              = msmqMessage.LookupId.Value;
                int               size              = msmqMessage.BodyLength.Value;
                int               offset            = 0;
                byte[]            incoming          = msmqMessage.Body.Buffer;
                MsmqReceiveHelper msmqReceiveHelper = listener.MsmqReceiveHelper;
                ServerModeDecoder modeDecoder       = new ServerModeDecoder();
                try
                {
                    ReadServerMode(listener, modeDecoder, incoming, messageProperty.LookupId, ref offset, ref size);
                }
                catch (ProtocolException exception)
                {
                    msmqReceiveHelper.FinalDisposition(messageProperty);
                    throw listener.NormalizePoisonException(messageProperty.LookupId, exception);
                }
                if (modeDecoder.Mode != FramingMode.Simplex)
                {
                    msmqReceiveHelper.FinalDisposition(messageProperty);
                    throw listener.NormalizePoisonException(messageProperty.LookupId, new ProtocolException(System.ServiceModel.SR.GetString("MsmqBadFrame")));
                }
                MsmqInputSessionChannel channel  = null;
                ServerSessionDecoder    decoder2 = new ServerSessionDecoder(0L, 0x800, 0x100);
                try
                {
                    do
                    {
                        if (size <= 0)
                        {
                            throw listener.NormalizePoisonException(messageProperty.LookupId, decoder2.CreatePrematureEOFException());
                        }
                        int num3 = decoder2.Decode(incoming, offset, size);
                        offset += num3;
                        size   -= num3;
                    }while (ServerSessionDecoder.State.EnvelopeStart != decoder2.CurrentState);
                }
                catch (ProtocolException exception2)
                {
                    msmqReceiveHelper.FinalDisposition(messageProperty);
                    throw listener.NormalizePoisonException(messageProperty.LookupId, exception2);
                }
                MessageEncoder encoder = listener.MessageEncoderFactory.CreateSessionEncoder();
                if (!encoder.IsContentTypeSupported(decoder2.ContentType))
                {
                    msmqReceiveHelper.FinalDisposition(messageProperty);
                    throw listener.NormalizePoisonException(messageProperty.LookupId, new ProtocolException(System.ServiceModel.SR.GetString("MsmqBadContentType")));
                }
                ReceiveContext sessiongramReceiveContext = null;
                if (msmqReceiveHelper.MsmqReceiveParameters.ReceiveContextSettings.Enabled)
                {
                    sessiongramReceiveContext = receiveContextManager.CreateMsmqReceiveContext(msmqMessage.LookupId.Value);
                }
                channel = new MsmqInputSessionChannel(listener, Transaction.Current, sessiongramReceiveContext);
                Message item = DecodeSessiongramMessage(listener, channel, encoder, messageProperty, incoming, offset, decoder2.EnvelopeSize);
                SecurityMessageProperty property = null;
                try
                {
                    property = listener.ValidateSecurity(msmqMessage);
                }
                catch (Exception exception3)
                {
                    if (Fx.IsFatal(exception3))
                    {
                        throw;
                    }
                    channel.FaultChannel();
                    msmqReceiveHelper.FinalDisposition(messageProperty);
                    throw listener.NormalizePoisonException(messageProperty.LookupId, exception3);
                }
                if (property != null)
                {
                    item.Properties.Security = property;
                }
                item.Properties["MsmqMessageProperty"] = messageProperty;
                channel.EnqueueAndDispatch(item);
                listener.RaiseMessageReceived();
Label_01F6:
                try
                {
                    if (size <= 0)
                    {
                        channel.FaultChannel();
                        msmqReceiveHelper.FinalDisposition(messageProperty);
                        throw listener.NormalizePoisonException(messageProperty.LookupId, decoder2.CreatePrematureEOFException());
                    }
                    num4 = decoder2.Decode(incoming, offset, size);
                }
                catch (ProtocolException exception4)
                {
                    channel.FaultChannel();
                    msmqReceiveHelper.FinalDisposition(messageProperty);
                    throw listener.NormalizePoisonException(messageProperty.LookupId, exception4);
                }
                offset += num4;
                size   -= num4;
                if (ServerSessionDecoder.State.End != decoder2.CurrentState)
                {
                    if (ServerSessionDecoder.State.EnvelopeStart == decoder2.CurrentState)
                    {
                        item = DecodeSessiongramMessage(listener, channel, encoder, messageProperty, incoming, offset, decoder2.EnvelopeSize);
                        if (property != null)
                        {
                            item.Properties.Security = (SecurityMessageProperty)property.CreateCopy();
                        }
                        item.Properties["MsmqMessageProperty"] = messageProperty;
                        channel.EnqueueAndDispatch(item);
                        listener.RaiseMessageReceived();
                    }
                    goto Label_01F6;
                }
                channel.Shutdown();
                MsmqDiagnostics.SessiongramReceived(channel.Session.Id, msmqMessage.MessageId, channel.InternalPendingItems);
                return(channel);
            }
        }