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