static object XmlDeserializeForIntegration(MsmqIntegrationChannelListener listener, Stream stream, long lookupId) { XmlTextReader reader = new XmlTextReader(stream); reader.WhitespaceHandling = WhitespaceHandling.Significant; reader.DtdProcessing = DtdProcessing.Prohibit; try { foreach (XmlSerializer serializer in listener.XmlSerializerList) { if (serializer.CanDeserialize(reader)) { return(serializer.Deserialize(reader)); } } } catch (InvalidOperationException e) { // XmlSerializer throws InvalidOperationException on failure of Deserialize. // We map it to SerializationException to provide consistent interface throw new SerializationException(e.Message); } throw new SerializationException(SR.GetString(SR.MsmqCannotDeserializeXmlMessage)); }
static object DeserializeForIntegration(MsmqIntegrationChannelListener listener, Stream bodyStream, MsmqIntegrationMessageProperty property, long lookupId) { MsmqMessageSerializationFormat serializationFormat = (listener.ReceiveParameters as MsmqIntegrationReceiveParameters).SerializationFormat; switch (serializationFormat) { case MsmqMessageSerializationFormat.Xml: return(XmlDeserializeForIntegration(listener, bodyStream, lookupId)); case MsmqMessageSerializationFormat.Binary: return(BinaryFormatter.Deserialize(bodyStream)); case MsmqMessageSerializationFormat.ActiveX: int bodyType = property.BodyType.Value; return(ActiveXSerializer.Deserialize(bodyStream as MemoryStream, bodyType)); case MsmqMessageSerializationFormat.ByteArray: return((bodyStream as MemoryStream).ToArray()); case MsmqMessageSerializationFormat.Stream: return(bodyStream); default: throw new SerializationException(SR.GetString(SR.MsmqUnsupportedSerializationFormat, serializationFormat)); } }
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); }
private static object XmlDeserializeForIntegration(MsmqIntegrationChannelListener listener, Stream stream, long lookupId) { XmlTextReader xmlReader = new XmlTextReader(stream) { WhitespaceHandling = WhitespaceHandling.Significant, DtdProcessing = DtdProcessing.Prohibit }; try { foreach (XmlSerializer serializer in listener.XmlSerializerList) { if (serializer.CanDeserialize(xmlReader)) { return(serializer.Deserialize(xmlReader)); } } } catch (InvalidOperationException exception) { throw new SerializationException(exception.Message); } throw new SerializationException(System.ServiceModel.SR.GetString("MsmqCannotDeserializeXmlMessage")); }
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(); } } } }