Ejemplo n.º 1
0
        public override IChannelListener <TChannel> BuildChannelListener <TChannel>(BindingContext context) where TChannel : class, IChannel
        {
            TransportChannelListener listener;

            if (context == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
            }
            MsmqTransportReceiveParameters receiveParameters = new MsmqTransportReceiveParameters(this, MsmqUri.NetMsmqAddressTranslator);

            if (typeof(TChannel) == typeof(IInputChannel))
            {
                listener = new MsmqInputChannelListener(this, context, receiveParameters);
            }
            else
            {
                if (typeof(TChannel) != typeof(IInputSessionChannel))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("TChannel", System.ServiceModel.SR.GetString("ChannelTypeNotSupported", new object[] { typeof(TChannel) }));
                }
                listener = new MsmqInputSessionChannelListener(this, context, receiveParameters);
            }
            AspNetEnvironment.Current.ApplyHostedContext(listener, context);
            MsmqVerifier.VerifyReceiver(receiveParameters, listener.Uri);
            return((IChannelListener <TChannel>)listener);
        }
Ejemplo n.º 2
0
        public override IChannelListener <TChannel> BuildChannelListener <TChannel>(BindingContext context)
        {
            if (context == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
            }

            TransportChannelListener msmqListener;

            MsmqTransportReceiveParameters receiveParameters = new MsmqTransportReceiveParameters(this, MsmqUri.NetMsmqAddressTranslator);

            if (typeof(TChannel) == typeof(IInputChannel))
            {
                msmqListener = new MsmqInputChannelListener(this, context, receiveParameters);
            }
            else if (typeof(TChannel) == typeof(IInputSessionChannel))
            {
                msmqListener = new MsmqInputSessionChannelListener(this, context, receiveParameters);
            }
            else
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("TChannel", SR.GetString(SR.ChannelTypeNotSupported, typeof(TChannel)));
            }
            AspNetEnvironment.Current.ApplyHostedContext(msmqListener, context);

            MsmqVerifier.VerifyReceiver(receiveParameters, msmqListener.Uri);

            return((IChannelListener <TChannel>)(object) msmqListener);
        }
 internal static Message DecodeTransportDatagram(MsmqInputChannelListener listener, MsmqReceiveHelper receiver, MsmqInputMessage msmqMessage, MsmqMessageProperty messageProperty)
 {
     Message message2;
     using (MsmqDiagnostics.BoundReceiveBytesOperation())
     {
         long num1 = msmqMessage.LookupId.Value;
         int size = msmqMessage.BodyLength.Value;
         int offset = 0;
         byte[] incoming = msmqMessage.Body.Buffer;
         ServerModeDecoder modeDecoder = new ServerModeDecoder();
         try
         {
             ReadServerMode(listener, modeDecoder, incoming, messageProperty.LookupId, ref offset, ref size);
         }
         catch (ProtocolException exception)
         {
             receiver.FinalDisposition(messageProperty);
             throw listener.NormalizePoisonException(messageProperty.LookupId, exception);
         }
         if (modeDecoder.Mode != FramingMode.SingletonSized)
         {
             receiver.FinalDisposition(messageProperty);
             throw listener.NormalizePoisonException(messageProperty.LookupId, new ProtocolException(System.ServiceModel.SR.GetString("MsmqBadFrame")));
         }
         ServerSingletonSizedDecoder decoder2 = new ServerSingletonSizedDecoder(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 (decoder2.CurrentState != ServerSingletonSizedDecoder.State.Start);
         }
         catch (ProtocolException exception2)
         {
             receiver.FinalDisposition(messageProperty);
             throw listener.NormalizePoisonException(messageProperty.LookupId, exception2);
         }
         if (size > listener.MaxReceivedMessageSize)
         {
             receiver.FinalDisposition(messageProperty);
             throw listener.NormalizePoisonException(messageProperty.LookupId, MaxMessageSizeStream.CreateMaxReceivedMessageSizeExceededException(listener.MaxReceivedMessageSize));
         }
         if (!listener.MessageEncoderFactory.Encoder.IsContentTypeSupported(decoder2.ContentType))
         {
             receiver.FinalDisposition(messageProperty);
             throw listener.NormalizePoisonException(messageProperty.LookupId, new ProtocolException(System.ServiceModel.SR.GetString("MsmqBadContentType")));
         }
         byte[] dst = listener.BufferManager.TakeBuffer(size);
         Buffer.BlockCopy(incoming, offset, dst, 0, size);
         Message message = null;
         using (MsmqDiagnostics.BoundDecodeOperation())
         {
             try
             {
                 message = listener.MessageEncoderFactory.Encoder.ReadMessage(new ArraySegment<byte>(dst, 0, size), listener.BufferManager);
             }
             catch (XmlException exception3)
             {
                 receiver.FinalDisposition(messageProperty);
                 throw listener.NormalizePoisonException(messageProperty.LookupId, new ProtocolException(System.ServiceModel.SR.GetString("MsmqBadXml"), exception3));
             }
             bool flag = true;
             try
             {
                 SecurityMessageProperty property = listener.ValidateSecurity(msmqMessage);
                 if (property != null)
                 {
                     message.Properties.Security = property;
                 }
                 flag = false;
                 MsmqDiagnostics.TransferFromTransport(message);
                 message2 = message;
             }
             catch (Exception exception4)
             {
                 if (Fx.IsFatal(exception4))
                 {
                     throw;
                 }
                 receiver.FinalDisposition(messageProperty);
                 throw listener.NormalizePoisonException(messageProperty.LookupId, exception4);
             }
             finally
             {
                 if (flag)
                 {
                     message.Close();
                 }
             }
         }
     }
     return message2;
 }
        internal static Message DecodeTransportDatagram(MsmqInputChannelListener listener, MsmqReceiveHelper receiver, MsmqInputMessage msmqMessage, MsmqMessageProperty messageProperty)
        {
            using (MsmqDiagnostics.BoundReceiveBytesOperation())
            {
                long lookupId = msmqMessage.LookupId.Value;
                int size = msmqMessage.BodyLength.Value;
                int offset = 0;
                byte[] incoming = msmqMessage.Body.Buffer;

                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.SingletonSized)
                {
                    receiver.FinalDisposition(messageProperty);
                    throw listener.NormalizePoisonException(messageProperty.LookupId, new ProtocolException(SR.GetString(SR.MsmqBadFrame)));
                }

                ServerSingletonSizedDecoder decoder = new ServerSingletonSizedDecoder(0, defaultMaxViaSize, defaultMaxContentTypeSize);
                try
                {
                    for (;;)
                    {
                        if (size <= 0)
                        {
                            throw listener.NormalizePoisonException(messageProperty.LookupId, decoder.CreatePrematureEOFException());
                        }

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

                if (size > listener.MaxReceivedMessageSize)
                {
                    receiver.FinalDisposition(messageProperty);
                    throw listener.NormalizePoisonException(messageProperty.LookupId, MaxMessageSizeStream.CreateMaxReceivedMessageSizeExceededException(listener.MaxReceivedMessageSize));
                }

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

                byte[] envelopeBuffer = listener.BufferManager.TakeBuffer(size);
                Buffer.BlockCopy(incoming, offset, envelopeBuffer, 0, size);

                Message message = null;

                using (MsmqDiagnostics.BoundDecodeOperation())
                {
                    try
                    {
                        message = listener.MessageEncoderFactory.Encoder.ReadMessage(
                            new ArraySegment<byte>(envelopeBuffer, 0, size), listener.BufferManager);
                    }
                    catch (XmlException e)
                    {
                        receiver.FinalDisposition(messageProperty);
                        throw listener.NormalizePoisonException(messageProperty.LookupId, new ProtocolException(SR.GetString(SR.MsmqBadXml), e));
                    }

                    bool closeMessage = true;
                    try
                    {
                        SecurityMessageProperty securityProperty = listener.ValidateSecurity(msmqMessage);
                        if (null != securityProperty)
                            message.Properties.Security = securityProperty;

                        closeMessage = false;
                        MsmqDiagnostics.TransferFromTransport(message);
                        return message;
                    }
                    catch (Exception ex)
                    {
                        if (Fx.IsFatal(ex))
                            throw;
                        receiver.FinalDisposition(messageProperty);
                        throw listener.NormalizePoisonException(messageProperty.LookupId, ex);
                    }
                    finally
                    {
                        if (closeMessage)
                        {
                            message.Close();
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        internal static Message DecodeTransportDatagram(MsmqInputChannelListener listener, MsmqReceiveHelper receiver, MsmqInputMessage msmqMessage, MsmqMessageProperty messageProperty)
        {
            using (MsmqDiagnostics.BoundReceiveBytesOperation())
            {
                long   lookupId = msmqMessage.LookupId.Value;
                int    size     = msmqMessage.BodyLength.Value;
                int    offset   = 0;
                byte[] incoming = msmqMessage.Body.Buffer;

                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.SingletonSized)
                {
                    receiver.FinalDisposition(messageProperty);
                    throw listener.NormalizePoisonException(messageProperty.LookupId, new ProtocolException(SR.GetString(SR.MsmqBadFrame)));
                }

                ServerSingletonSizedDecoder decoder = new ServerSingletonSizedDecoder(0, defaultMaxViaSize, defaultMaxContentTypeSize);
                try
                {
                    for (;;)
                    {
                        if (size <= 0)
                        {
                            throw listener.NormalizePoisonException(messageProperty.LookupId, decoder.CreatePrematureEOFException());
                        }

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

                if (size > listener.MaxReceivedMessageSize)
                {
                    receiver.FinalDisposition(messageProperty);
                    throw listener.NormalizePoisonException(messageProperty.LookupId, MaxMessageSizeStream.CreateMaxReceivedMessageSizeExceededException(listener.MaxReceivedMessageSize));
                }

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

                byte[] envelopeBuffer = listener.BufferManager.TakeBuffer(size);
                Buffer.BlockCopy(incoming, offset, envelopeBuffer, 0, size);

                Message message = null;

                using (MsmqDiagnostics.BoundDecodeOperation())
                {
                    try
                    {
                        message = listener.MessageEncoderFactory.Encoder.ReadMessage(
                            new ArraySegment <byte>(envelopeBuffer, 0, size), listener.BufferManager);
                    }
                    catch (XmlException e)
                    {
                        receiver.FinalDisposition(messageProperty);
                        throw listener.NormalizePoisonException(messageProperty.LookupId, new ProtocolException(SR.GetString(SR.MsmqBadXml), e));
                    }

                    bool closeMessage = true;
                    try
                    {
                        SecurityMessageProperty securityProperty = listener.ValidateSecurity(msmqMessage);
                        if (null != securityProperty)
                        {
                            message.Properties.Security = securityProperty;
                        }

                        closeMessage = false;
                        MsmqDiagnostics.TransferFromTransport(message);
                        return(message);
                    }
                    catch (Exception ex)
                    {
                        if (Fx.IsFatal(ex))
                        {
                            throw;
                        }
                        receiver.FinalDisposition(messageProperty);
                        throw listener.NormalizePoisonException(messageProperty.LookupId, ex);
                    }
                    finally
                    {
                        if (closeMessage)
                        {
                            message.Close();
                        }
                    }
                }
            }
        }
 public MsmqInputChannel(MsmqInputChannelListener listener) : base(listener, new MsmqInputMessagePool((listener.ReceiveParameters as MsmqTransportReceiveParameters).MaxPoolSize))
 {
 }
        internal static Message DecodeTransportDatagram(MsmqInputChannelListener listener, MsmqReceiveHelper receiver, MsmqInputMessage msmqMessage, MsmqMessageProperty messageProperty)
        {
            Message message2;

            using (MsmqDiagnostics.BoundReceiveBytesOperation())
            {
                long              num1        = msmqMessage.LookupId.Value;
                int               size        = msmqMessage.BodyLength.Value;
                int               offset      = 0;
                byte[]            incoming    = msmqMessage.Body.Buffer;
                ServerModeDecoder modeDecoder = new ServerModeDecoder();
                try
                {
                    ReadServerMode(listener, modeDecoder, incoming, messageProperty.LookupId, ref offset, ref size);
                }
                catch (ProtocolException exception)
                {
                    receiver.FinalDisposition(messageProperty);
                    throw listener.NormalizePoisonException(messageProperty.LookupId, exception);
                }
                if (modeDecoder.Mode != FramingMode.SingletonSized)
                {
                    receiver.FinalDisposition(messageProperty);
                    throw listener.NormalizePoisonException(messageProperty.LookupId, new ProtocolException(System.ServiceModel.SR.GetString("MsmqBadFrame")));
                }
                ServerSingletonSizedDecoder decoder2 = new ServerSingletonSizedDecoder(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 (decoder2.CurrentState != ServerSingletonSizedDecoder.State.Start);
                }
                catch (ProtocolException exception2)
                {
                    receiver.FinalDisposition(messageProperty);
                    throw listener.NormalizePoisonException(messageProperty.LookupId, exception2);
                }
                if (size > listener.MaxReceivedMessageSize)
                {
                    receiver.FinalDisposition(messageProperty);
                    throw listener.NormalizePoisonException(messageProperty.LookupId, MaxMessageSizeStream.CreateMaxReceivedMessageSizeExceededException(listener.MaxReceivedMessageSize));
                }
                if (!listener.MessageEncoderFactory.Encoder.IsContentTypeSupported(decoder2.ContentType))
                {
                    receiver.FinalDisposition(messageProperty);
                    throw listener.NormalizePoisonException(messageProperty.LookupId, new ProtocolException(System.ServiceModel.SR.GetString("MsmqBadContentType")));
                }
                byte[] dst = listener.BufferManager.TakeBuffer(size);
                Buffer.BlockCopy(incoming, offset, dst, 0, size);
                Message message = null;
                using (MsmqDiagnostics.BoundDecodeOperation())
                {
                    try
                    {
                        message = listener.MessageEncoderFactory.Encoder.ReadMessage(new ArraySegment <byte>(dst, 0, size), listener.BufferManager);
                    }
                    catch (XmlException exception3)
                    {
                        receiver.FinalDisposition(messageProperty);
                        throw listener.NormalizePoisonException(messageProperty.LookupId, new ProtocolException(System.ServiceModel.SR.GetString("MsmqBadXml"), exception3));
                    }
                    bool flag = true;
                    try
                    {
                        SecurityMessageProperty property = listener.ValidateSecurity(msmqMessage);
                        if (property != null)
                        {
                            message.Properties.Security = property;
                        }
                        flag = false;
                        MsmqDiagnostics.TransferFromTransport(message);
                        message2 = message;
                    }
                    catch (Exception exception4)
                    {
                        if (Fx.IsFatal(exception4))
                        {
                            throw;
                        }
                        receiver.FinalDisposition(messageProperty);
                        throw listener.NormalizePoisonException(messageProperty.LookupId, exception4);
                    }
                    finally
                    {
                        if (flag)
                        {
                            message.Close();
                        }
                    }
                }
            }
            return(message2);
        }
Ejemplo n.º 8
0
 public MsmqInputChannel(MsmqInputChannelListener listener) : base(listener, new MsmqInputMessagePool((listener.ReceiveParameters as MsmqTransportReceiveParameters).MaxPoolSize))
 {
 }
Ejemplo n.º 9
0
        protected override Message DecodeMsmqMessage(MsmqInputMessage msmqMessage, MsmqMessageProperty messageProperty)
        {
            MsmqInputChannelListener manager = base.Manager as MsmqInputChannelListener;

            return(MsmqDecodeHelper.DecodeTransportDatagram(manager, base.MsmqReceiveHelper, msmqMessage, messageProperty));
        }