public static Activity BoundReceiveOperation(MsmqReceiveHelper receiver)
 {
     if ((DiagnosticUtility.ShouldUseActivity && (ServiceModelActivity.Current != null)) && (ActivityType.ProcessAction != ServiceModelActivity.Current.ActivityType))
     {
         return ServiceModelActivity.BoundOperation(receiver.Activity);
     }
     return null;
 }
 public static Activity BoundOpenOperation(MsmqReceiveHelper receiver)
 {
     if (DiagnosticUtility.ShouldTraceInformation)
     {
         TraceUtility.TraceEvent(TraceEventType.Information, 0x80036, System.ServiceModel.SR.GetString("TraceCodeTransportListen", new object[] { receiver.ListenUri.ToString() }), receiver);
     }
     return ServiceModelActivity.BoundOperation(receiver.Activity);
 }
 public Msmq4PoisonHandler(MsmqReceiveHelper receiver)
 {
     this.receiver = receiver;
     this.timer = new IOThreadTimer(new Action<object>(OnTimer), null, false);
     this.disposed = false;
     this.mainQueueName = this.ReceiveParameters.AddressTranslator.UriToFormatName(this.ListenUri);
     this.poisonQueueName = this.ReceiveParameters.AddressTranslator.UriToFormatName(new Uri(this.ListenUri.AbsoluteUri + ";poison"));
     this.retryQueueName = this.ReceiveParameters.AddressTranslator.UriToFormatName(new Uri(this.ListenUri.AbsoluteUri + ";retry"));
 }
 internal static Message DecodeIntegrationDatagram(MsmqIntegrationChannelListener listener, MsmqReceiveHelper receiver, MsmqIntegrationInputMessage msmqMessage, MsmqMessageProperty messageProperty)
 {
     Message message2;
     using (MsmqDiagnostics.BoundReceiveBytesOperation())
     {
         Message message = Message.CreateMessage(MessageVersion.None, (string) null);
         bool flag = true;
         try
         {
             SecurityMessageProperty property = listener.ValidateSecurity(msmqMessage);
             if (property != null)
             {
                 message.Properties.Security = property;
             }
             MsmqIntegrationMessageProperty property2 = new MsmqIntegrationMessageProperty();
             msmqMessage.SetMessageProperties(property2);
             int length = msmqMessage.BodyLength.Value;
             if (length > listener.MaxReceivedMessageSize)
             {
                 receiver.FinalDisposition(messageProperty);
                 throw listener.NormalizePoisonException(messageProperty.LookupId, MaxMessageSizeStream.CreateMaxReceivedMessageSizeExceededException(listener.MaxReceivedMessageSize));
             }
             byte[] bufferCopy = msmqMessage.Body.GetBufferCopy(length);
             MemoryStream bodyStream = new MemoryStream(bufferCopy, 0, bufferCopy.Length, false);
             object obj2 = null;
             using (MsmqDiagnostics.BoundDecodeOperation())
             {
                 try
                 {
                     obj2 = DeserializeForIntegration(listener, bodyStream, property2, messageProperty.LookupId);
                 }
                 catch (SerializationException exception)
                 {
                     receiver.FinalDisposition(messageProperty);
                     throw listener.NormalizePoisonException(messageProperty.LookupId, new ProtocolException(System.ServiceModel.SR.GetString("MsmqDeserializationError"), exception));
                 }
                 property2.Body = obj2;
                 message.Properties["MsmqIntegrationMessageProperty"] = property2;
                 bodyStream.Seek(0L, SeekOrigin.Begin);
                 message.Headers.To = listener.Uri;
                 flag = false;
                 MsmqDiagnostics.TransferFromTransport(message);
             }
             message2 = message;
         }
         finally
         {
             if (flag)
             {
                 message.Close();
             }
         }
     }
     return message2;
 }
Пример #5
0
 internal TryTransactedReceiveAsyncResult(MsmqReceiveHelper receiver, MsmqInputMessage msmqMessage,
                                          TimeSpan timeout, MsmqTransactionMode transactionMode, AsyncCallback callback, object state)
     : base(callback, state)
 {
     this.timeoutHelper   = new TimeoutHelper(timeout);
     this.txCurrent       = Transaction.Current;
     this.receiver        = receiver;
     this.msmqMessage     = msmqMessage;
     this.transactionMode = transactionMode;
     ActionItem.Schedule(onComplete, this);
 }
 public static Activity BoundReceiveOperation(MsmqReceiveHelper receiver)
 {
     if (DiagnosticUtility.ShouldUseActivity && null != ServiceModelActivity.Current && ActivityType.ProcessAction != ServiceModelActivity.Current.ActivityType)
     {
         return(ServiceModelActivity.BoundOperation(receiver.Activity));
     }
     else
     {
         return(null);
     }
 }
 public MsmqInputChannelBase(MsmqInputChannelListenerBase listener, IMsmqMessagePool messagePool)
     : base(listener)
 {
     this.receiveParameters = listener.ReceiveParameters;
     this.receiver          = new MsmqReceiveHelper(listener.ReceiveParameters, listener.Uri, messagePool, this, listener);
     this.localAddress      = new EndpointAddress(listener.Uri);
     this.listener          = listener;
     if (this.receiveParameters.ReceiveContextSettings.Enabled)
     {
         this.receiveContextManager = new MsmqReceiveContextLockManager(this.receiveParameters.ReceiveContextSettings, this.receiver.Queue);
     }
 }
Пример #8
0
 internal static MsmqQueue CreateMsmqQueue(MsmqReceiveHelper receiver)
 {
     if (!receiver.MsmqReceiveParameters.ReceiveContextSettings.Enabled)
     {
         return(new MsmqQueue(receiver.MsmqReceiveParameters.AddressTranslator.UriToFormatName(receiver.ListenUri), 1));
     }
     if (Version < longhornVersion)
     {
         return(new MsmqDefaultLockingQueue(receiver.MsmqReceiveParameters.AddressTranslator.UriToFormatName(receiver.ListenUri), 1));
     }
     return(new MsmqSubqueueLockingQueue(receiver.MsmqReceiveParameters.AddressTranslator.UriToFormatName(receiver.ListenUri), receiver.ListenUri.Host, 1));
 }
 public static Activity BoundOpenOperation(MsmqReceiveHelper receiver)
 {
     if (DiagnosticUtility.ShouldTraceInformation)
     {
         TraceUtility.TraceEvent(
             TraceEventType.Information,
             TraceCode.TransportListen,
             SR.GetString(SR.TraceCodeTransportListen, receiver.ListenUri.ToString()),
             receiver);
     }
     return(ServiceModelActivity.BoundOperation(receiver.Activity));
 }
 public static Activity BoundOpenOperation(MsmqReceiveHelper receiver)
 {
     if (DiagnosticUtility.ShouldTraceInformation)
     {
         TraceUtility.TraceEvent(
             TraceEventType.Information,
             TraceCode.TransportListen,
             SR.GetString(SR.TraceCodeTransportListen, receiver.ListenUri.ToString()),
             receiver);
     }
     return ServiceModelActivity.BoundOperation(receiver.Activity);
 }
 internal static MsmqQueue CreateMsmqQueue(MsmqReceiveHelper receiver)
 {
     if (!receiver.MsmqReceiveParameters.ReceiveContextSettings.Enabled)
     {
         return new MsmqQueue(receiver.MsmqReceiveParameters.AddressTranslator.UriToFormatName(receiver.ListenUri), 1);
     }
     if (Version < longhornVersion)
     {
         return new MsmqDefaultLockingQueue(receiver.MsmqReceiveParameters.AddressTranslator.UriToFormatName(receiver.ListenUri), 1);
     }
     return new MsmqSubqueueLockingQueue(receiver.MsmqReceiveParameters.AddressTranslator.UriToFormatName(receiver.ListenUri), receiver.ListenUri.Host, 1);
 }
 public MsmqInputChannelBase(MsmqInputChannelListenerBase listener, IMsmqMessagePool messagePool)
     : base(listener)
 {
     this.receiveParameters = listener.ReceiveParameters;
     this.receiver = new MsmqReceiveHelper(listener.ReceiveParameters, listener.Uri, messagePool, this, listener);
     this.localAddress = new EndpointAddress(listener.Uri);
     this.listener = listener;
     if (this.receiveParameters.ReceiveContextSettings.Enabled)
     {
         this.receiveContextManager = new MsmqReceiveContextLockManager(this.receiveParameters.ReceiveContextSettings, this.receiver.Queue);
     }
 }
 public static ServiceModelActivity StartListenAtActivity(MsmqReceiveHelper receiver)
 {
     ServiceModelActivity activity = receiver.Activity;
     if (DiagnosticUtility.ShouldUseActivity && null == activity)
     {
         activity = ServiceModelActivity.CreateActivity(true);
         if (null != FxTrace.Trace)
         {
             FxTrace.Trace.TraceTransfer(activity.Id);
         }
         ServiceModelActivity.Start(activity, SR.GetString(SR.ActivityListenAt, receiver.ListenUri.ToString()), ActivityType.ListenAt);
     }
     return activity;
 }
Пример #14
0
        public static ServiceModelActivity StartListenAtActivity(MsmqReceiveHelper receiver)
        {
            ServiceModelActivity activity = receiver.Activity;

            if (DiagnosticUtility.ShouldUseActivity && (activity == null))
            {
                activity = ServiceModelActivity.CreateActivity(true);
                if (FxTrace.Trace != null)
                {
                    FxTrace.Trace.TraceTransfer(activity.Id);
                }
                ServiceModelActivity.Start(activity, System.ServiceModel.SR.GetString("ActivityListenAt", new object[] { receiver.ListenUri.ToString() }), ActivityType.ListenAt);
            }
            return(activity);
        }
        public static ServiceModelActivity StartListenAtActivity(MsmqReceiveHelper receiver)
        {
            ServiceModelActivity activity = receiver.Activity;

            if (DiagnosticUtility.ShouldUseActivity && null == activity)
            {
                activity = ServiceModelActivity.CreateActivity(true);
                if (null != FxTrace.Trace)
                {
                    FxTrace.Trace.TraceTransfer(activity.Id);
                }
                ServiceModelActivity.Start(activity, SR.GetString(SR.ActivityListenAt, receiver.ListenUri.ToString()), ActivityType.ListenAt);
            }
            return(activity);
        }
Пример #16
0
 internal static IPoisonHandlingStrategy CreatePoisonHandler(MsmqReceiveHelper receiver)
 {
     if (!receiver.Transactional)
     {
         return(new MsmqNonTransactedPoisonHandler(receiver));
     }
     if (Version < longhornVersion)
     {
         return(new Msmq3PoisonHandler(receiver));
     }
     if (receiver.ListenUri.AbsoluteUri.Contains(";"))
     {
         return(new Msmq4SubqueuePoisonHandler(receiver));
     }
     return(new Msmq4PoisonHandler(receiver));
 }
 internal static IPoisonHandlingStrategy CreatePoisonHandler(MsmqReceiveHelper receiver)
 {
     if (!receiver.Transactional)
     {
         return new MsmqNonTransactedPoisonHandler(receiver);
     }
     if (Version < longhornVersion)
     {
         return new Msmq3PoisonHandler(receiver);
     }
     if (receiver.ListenUri.AbsoluteUri.Contains(";"))
     {
         return new Msmq4SubqueuePoisonHandler(receiver);
     }
     return new Msmq4PoisonHandler(receiver);
 }
        internal MsmqInputSessionChannelListener(MsmqBindingElementBase bindingElement, BindingContext context, MsmqReceiveParameters receiveParameters)
            : base(bindingElement, context, receiveParameters, TransportDefaults.GetDefaultMessageEncoderFactory())
        {
            SetSecurityTokenAuthenticator(MsmqUri.NetMsmqAddressTranslator.Scheme, context);
            this.receiver = new MsmqReceiveHelper(
                this.ReceiveParameters,
                this.Uri,
                new MsmqInputMessagePool((this.ReceiveParameters as MsmqTransportReceiveParameters).MaxPoolSize),
                null,
                this
                );

            if (this.ReceiveParameters.ReceiveContextSettings.Enabled)
            {
                this.receiveContextManager = new MsmqReceiveContextLockManager(this.ReceiveParameters.ReceiveContextSettings, this.receiver.Queue);
            }
        }
Пример #19
0
 internal static MsmqQueue CreateMsmqQueue(MsmqReceiveHelper receiver)
 {
     if (receiver.MsmqReceiveParameters.ReceiveContextSettings.Enabled)
     {
         if (Msmq.Version < longhornVersion)
         {
             return(new MsmqDefaultLockingQueue(receiver.MsmqReceiveParameters.AddressTranslator.UriToFormatName(receiver.ListenUri), UnsafeNativeMethods.MQ_RECEIVE_ACCESS));
         }
         else
         {
             return(new MsmqSubqueueLockingQueue(receiver.MsmqReceiveParameters.AddressTranslator.UriToFormatName(receiver.ListenUri), receiver.ListenUri.Host, UnsafeNativeMethods.MQ_RECEIVE_ACCESS));
         }
     }
     else
     {
         return(new MsmqQueue(receiver.MsmqReceiveParameters.AddressTranslator.UriToFormatName(receiver.ListenUri), UnsafeNativeMethods.MQ_RECEIVE_ACCESS));
     }
 }
        public void FinalDisposition(MsmqMessageProperty messageProperty)
        {
            switch (this.receiver.MsmqReceiveParameters.ReceiveErrorHandling)
            {
            case ReceiveErrorHandling.Fault:
                MsmqReceiveHelper.TryAbortTransactionCurrent();
                if (this.receiver.ChannelListener != null)
                {
                    this.receiver.ChannelListener.FaultListener();
                }
                if (this.receiver.Channel != null)
                {
                    this.receiver.Channel.FaultChannel();
                }
                return;

            case ReceiveErrorHandling.Drop:
                this.receiver.DropOrRejectReceivedMessage(messageProperty, false);
                return;
            }
        }
Пример #21
0
        public bool ReceiveContextPoisonHandling(MsmqMessageProperty messageProperty)
        {
            int num            = this.ReceiveParameters.ReceiveRetryCount + 1;
            int maxRetryCycles = this.ReceiveParameters.MaxRetryCycles;
            int num3           = (2 * num) + 1;
            int num4           = messageProperty.MoveCount / (num3 + 2);
            int num5           = num4 * (num3 + 2);
            int num6           = messageProperty.MoveCount - num5;

            lock (this)
            {
                if (this.disposed)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ObjectDisposedException(base.GetType().ToString()));
                }
                if (num4 > maxRetryCycles)
                {
                    this.FinalDisposition(messageProperty);
                    return(true);
                }
                if (num6 >= num3)
                {
                    if (num4 < maxRetryCycles)
                    {
                        MsmqReceiveHelper.MoveReceivedMessage(this.lockQueueForReceive, this.retryQueueForMove, messageProperty.LookupId);
                        MsmqDiagnostics.PoisonMessageMoved(messageProperty.MessageId, false, this.receiver.InstanceId);
                    }
                    else
                    {
                        this.FinalDisposition(messageProperty);
                    }
                    return(true);
                }
                return(false);
            }
        }
        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);
            }
        }
Пример #23
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);
            }
        }
 public static ServiceModelActivity StartListenAtActivity(MsmqReceiveHelper receiver)
 {
     ServiceModelActivity activity = receiver.Activity;
     if (DiagnosticUtility.ShouldUseActivity && (activity == null))
     {
         activity = ServiceModelActivity.CreateActivity(true);
         if (FxTrace.Trace != null)
         {
             FxTrace.Trace.TraceTransfer(activity.Id);
         }
         ServiceModelActivity.Start(activity, System.ServiceModel.SR.GetString("ActivityListenAt", new object[] { receiver.ListenUri.ToString() }), ActivityType.ListenAt);
     }
     return activity;
 }
Пример #25
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();
                        }
                    }
                }
            }
        }
Пример #26
0
        internal static Message DecodeIntegrationDatagram(MsmqIntegrationChannelListener listener, MsmqReceiveHelper receiver, MsmqIntegrationInputMessage msmqMessage, MsmqMessageProperty messageProperty)
        {
            using (MsmqDiagnostics.BoundReceiveBytesOperation())
            {
                Message message      = Message.CreateMessage(MessageVersion.None, (string)null);
                bool    closeMessage = true;

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

                    MsmqIntegrationMessageProperty integrationProperty = new MsmqIntegrationMessageProperty();
                    msmqMessage.SetMessageProperties(integrationProperty);

                    int size = msmqMessage.BodyLength.Value;

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

                    byte[] bodyBytes = msmqMessage.Body.GetBufferCopy(size);

                    MemoryStream bodyStream = new MemoryStream(bodyBytes, 0, bodyBytes.Length, false);

                    object body = null;
                    using (MsmqDiagnostics.BoundDecodeOperation())
                    {
                        try
                        {
                            body = DeserializeForIntegration(listener, bodyStream, integrationProperty, messageProperty.LookupId);
                        }
                        catch (SerializationException e)
                        {
                            receiver.FinalDisposition(messageProperty);
                            throw listener.NormalizePoisonException(messageProperty.LookupId, new ProtocolException(SR.GetString(SR.MsmqDeserializationError), e));
                        }

                        integrationProperty.Body = body;
                        message.Properties[MsmqIntegrationMessageProperty.Name] = integrationProperty;
                        bodyStream.Seek(0, SeekOrigin.Begin);
                        message.Headers.To = listener.Uri;
                        closeMessage       = false;
                        MsmqDiagnostics.TransferFromTransport(message);
                    }
                    return(message);
                }
                finally
                {
                    if (closeMessage)
                    {
                        message.Close();
                    }
                }
            }
        }
 internal TryNonTransactedReceiveAsyncResult(MsmqReceiveHelper receiver, MsmqInputMessage msmqMessage, TimeSpan timeout, AsyncCallback callback, object state)
     : base(callback, state)
 {
     this.receiver = receiver;
     this.msmqMessage = msmqMessage;
     receiver.Queue.BeginTryReceive(msmqMessage, timeout, onCompleteStatic, this);
 }
 internal TryNonTransactedReceiveAsyncResult(MsmqReceiveHelper receiver, MsmqInputMessage msmqMessage, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state)
 {
     this.receiver    = receiver;
     this.msmqMessage = msmqMessage;
     receiver.Queue.BeginTryReceive(msmqMessage, timeout, onCompleteStatic, this);
 }
 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 MsmqNonTransactedPoisonHandler(MsmqReceiveHelper receiver)
 {
     this.receiver = receiver;
 }
        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 Msmq4SubqueuePoisonHandler(MsmqReceiveHelper receiver)
 {
     this.receiver = receiver;
 }
        internal static Message DecodeIntegrationDatagram(MsmqIntegrationChannelListener listener, MsmqReceiveHelper receiver, MsmqIntegrationInputMessage msmqMessage, MsmqMessageProperty messageProperty)
        {
            using (MsmqDiagnostics.BoundReceiveBytesOperation())
            {
                Message message = Message.CreateMessage(MessageVersion.None, (string)null);
                bool closeMessage = true;

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

                    MsmqIntegrationMessageProperty integrationProperty = new MsmqIntegrationMessageProperty();
                    msmqMessage.SetMessageProperties(integrationProperty);

                    int size = msmqMessage.BodyLength.Value;

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

                    byte[] bodyBytes = msmqMessage.Body.GetBufferCopy(size);

                    MemoryStream bodyStream = new MemoryStream(bodyBytes, 0, bodyBytes.Length, false);

                    object body = null;
                    using (MsmqDiagnostics.BoundDecodeOperation())
                    {
                        try
                        {
                            body = DeserializeForIntegration(listener, bodyStream, integrationProperty, messageProperty.LookupId);
                        }
                        catch (SerializationException e)
                        {
                            receiver.FinalDisposition(messageProperty);
                            throw listener.NormalizePoisonException(messageProperty.LookupId, new ProtocolException(SR.GetString(SR.MsmqDeserializationError), e));
                        }

                        integrationProperty.Body = body;
                        message.Properties[MsmqIntegrationMessageProperty.Name] = integrationProperty;
                        bodyStream.Seek(0, SeekOrigin.Begin);
                        message.Headers.To = listener.Uri;
                        closeMessage = false;
                        MsmqDiagnostics.TransferFromTransport(message);
                    }
                    return message;
                }
                finally
                {
                    if (closeMessage)
                        message.Close();
                }
            }
        }
 internal TryTransactedReceiveAsyncResult(MsmqReceiveHelper receiver, MsmqInputMessage msmqMessage,
     TimeSpan timeout, MsmqTransactionMode transactionMode, AsyncCallback callback, object state)
     : base(callback, state)
 {
     this.timeoutHelper = new TimeoutHelper(timeout);
     this.txCurrent = Transaction.Current;
     this.receiver = receiver;
     this.msmqMessage = msmqMessage;
     this.transactionMode = transactionMode;
     ActionItem.Schedule(onComplete, this);
 }
Пример #35
0
 internal static MsmqQueue CreateMsmqQueue(MsmqReceiveHelper receiver)
 {
     if (receiver.MsmqReceiveParameters.ReceiveContextSettings.Enabled)
     {
         if (Msmq.Version < longhornVersion)
         {
             return new MsmqDefaultLockingQueue(receiver.MsmqReceiveParameters.AddressTranslator.UriToFormatName(receiver.ListenUri), UnsafeNativeMethods.MQ_RECEIVE_ACCESS);
         }
         else
         {
             return new MsmqSubqueueLockingQueue(receiver.MsmqReceiveParameters.AddressTranslator.UriToFormatName(receiver.ListenUri), receiver.ListenUri.Host, UnsafeNativeMethods.MQ_RECEIVE_ACCESS);
         }
     }
     else
     {
         return new MsmqQueue(receiver.MsmqReceiveParameters.AddressTranslator.UriToFormatName(receiver.ListenUri), UnsafeNativeMethods.MQ_RECEIVE_ACCESS);
     }
 }
        public bool ReceiveContextPoisonHandling(MsmqMessageProperty messageProperty)
        {
            // The basic idea is to use the message move count to get the number of retry attempts the message has been through
            // The computation of the retry count and retry cycle count is slightly involved due to fact that the message being processed
            // could have been recycled message. (Recycled message is the message that moves from lock queue to retry queue to main queue
            // and back to lock queue
            //

            // Count to tally message recycling (lock queue to retry queue to main queue adds move count of 2 to the message)
            const int retryMoveCount = 2;

            // Actual number of times message is received before recycling to retry queue
            int actualReceiveRetryCount = this.ReceiveParameters.ReceiveRetryCount + 1;

            // The message is recycled these many number of times
            int maxRetryCycles = this.ReceiveParameters.MaxRetryCycles;

            // Max change in message move count between recycling
            int maxMovePerCycle = (2 * actualReceiveRetryCount) + 1;

            // Number of recycles the message has been through
            int messageCyclesCompleted = messageProperty.MoveCount / (maxMovePerCycle + retryMoveCount);

            // Total number of moves on the message at the end of the last recycle
            int messageMoveCountForCyclesCompleted = messageCyclesCompleted * (maxMovePerCycle + retryMoveCount);

            // The differential move count for the current cycle
            int messageMoveCountForCurrentCycle = messageProperty.MoveCount - messageMoveCountForCyclesCompleted;

            lock (this)
            {
                if (this.disposed)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ObjectDisposedException(this.GetType().ToString()));
                }

                // Check if the message has already completed its max recycle count (MaxRetryCycles)
                // and the disposed the message first. Such a message was previously disposed using the ReceiveErrorHandling method
                // and the channel/listener would immediately fault
                //
                if (messageCyclesCompleted > maxRetryCycles)
                {
                    FinalDisposition(messageProperty);
                    return(true);
                }

                // Check if the message is eligible for recycling/disposition
                if (messageMoveCountForCurrentCycle >= maxMovePerCycle)
                {
                    if (TD.ReceiveRetryCountReachedIsEnabled())
                    {
                        TD.ReceiveRetryCountReached(messageProperty.MessageId);
                    }
                    if (messageCyclesCompleted < maxRetryCycles)
                    {
                        // The message is eligible for recycling, move the message the message to retry queue
                        MsmqReceiveHelper.MoveReceivedMessage(this.lockQueueForReceive, this.retryQueueForMove, messageProperty.LookupId);
                        MsmqDiagnostics.PoisonMessageMoved(messageProperty.MessageId, false, this.receiver.InstanceId);
                    }
                    else
                    {
                        if (TD.MaxRetryCyclesExceededMsmqIsEnabled())
                        {
                            TD.MaxRetryCyclesExceededMsmq(messageProperty.MessageId);
                        }
                        // Dispose the message using ReceiveErrorHandling
                        FinalDisposition(messageProperty);
                    }

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
 internal Msmq3PoisonHandler(MsmqReceiveHelper receiver)
 {
     this.receiver        = receiver;
     this.trackedMessages = new SortedList <long, int>(maxTrackedMessages);
 }
 public Msmq4SubqueuePoisonHandler(MsmqReceiveHelper receiver)
 {
     this.receiver = receiver;
 }
        internal static Message DecodeIntegrationDatagram(MsmqIntegrationChannelListener listener, MsmqReceiveHelper receiver, MsmqIntegrationInputMessage msmqMessage, MsmqMessageProperty messageProperty)
        {
            Message message2;

            using (MsmqDiagnostics.BoundReceiveBytesOperation())
            {
                Message message = Message.CreateMessage(MessageVersion.None, (string)null);
                bool    flag    = true;
                try
                {
                    SecurityMessageProperty property = listener.ValidateSecurity(msmqMessage);
                    if (property != null)
                    {
                        message.Properties.Security = property;
                    }
                    MsmqIntegrationMessageProperty property2 = new MsmqIntegrationMessageProperty();
                    msmqMessage.SetMessageProperties(property2);
                    int length = msmqMessage.BodyLength.Value;
                    if (length > listener.MaxReceivedMessageSize)
                    {
                        receiver.FinalDisposition(messageProperty);
                        throw listener.NormalizePoisonException(messageProperty.LookupId, MaxMessageSizeStream.CreateMaxReceivedMessageSizeExceededException(listener.MaxReceivedMessageSize));
                    }
                    byte[]       bufferCopy = msmqMessage.Body.GetBufferCopy(length);
                    MemoryStream bodyStream = new MemoryStream(bufferCopy, 0, bufferCopy.Length, false);
                    object       obj2       = null;
                    using (MsmqDiagnostics.BoundDecodeOperation())
                    {
                        try
                        {
                            obj2 = DeserializeForIntegration(listener, bodyStream, property2, messageProperty.LookupId);
                        }
                        catch (SerializationException exception)
                        {
                            receiver.FinalDisposition(messageProperty);
                            throw listener.NormalizePoisonException(messageProperty.LookupId, new ProtocolException(System.ServiceModel.SR.GetString("MsmqDeserializationError"), exception));
                        }
                        property2.Body = obj2;
                        message.Properties["MsmqIntegrationMessageProperty"] = property2;
                        bodyStream.Seek(0L, SeekOrigin.Begin);
                        message.Headers.To = listener.Uri;
                        flag = false;
                        MsmqDiagnostics.TransferFromTransport(message);
                    }
                    message2 = message;
                }
                finally
                {
                    if (flag)
                    {
                        message.Close();
                    }
                }
            }
            return(message2);
        }
 internal Msmq3PoisonHandler(MsmqReceiveHelper receiver)
 {
     this.receiver = receiver;
     this.trackedMessages = new SortedList<long, int>(0x100);
 }
        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);
        }