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); } }
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); } }