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;
 }
        public override IChannelListener <TChannel> BuildChannelListener <TChannel>(BindingContext context) where TChannel : class, IChannel
        {
            if (context == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
            }
            if (typeof(TChannel) != typeof(IInputChannel))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("TChannel", System.ServiceModel.SR.GetString("ChannelTypeNotSupported", new object[] { typeof(TChannel) }));
            }
            MsmqIntegrationReceiveParameters receiveParameters = new MsmqIntegrationReceiveParameters(this);
            MsmqIntegrationChannelListener   listener          = new MsmqIntegrationChannelListener(this, context, receiveParameters);

            MsmqVerifier.VerifyReceiver(receiveParameters, listener.Uri);
            return((IChannelListener <TChannel>)listener);
        }
 public MsmqIntegrationInputChannel(MsmqIntegrationChannelListener listener)
     : base(listener, new MsmqIntegrationMessagePool(MsmqDefaults.MaxPoolSize))
 { }
 public MsmqIntegrationInputChannel(MsmqIntegrationChannelListener listener) : base(listener, new MsmqIntegrationMessagePool(8))
 {
 }
 public MsmqIntegrationInputChannel(MsmqIntegrationChannelListener listener) : base(listener, new MsmqIntegrationMessagePool(8))
 {
 }
        protected override Message DecodeMsmqMessage(MsmqInputMessage msmqMessage, MsmqMessageProperty property)
        {
            MsmqIntegrationChannelListener manager = base.Manager as MsmqIntegrationChannelListener;

            return(MsmqDecodeHelper.DecodeIntegrationDatagram(manager, base.MsmqReceiveHelper, msmqMessage as MsmqIntegrationInputMessage, property));
        }
 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"));
 }
        private 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;
            }
            throw new SerializationException(System.ServiceModel.SR.GetString("MsmqUnsupportedSerializationFormat", new object[] { serializationFormat }));
        }
        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));
        }
        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();
                }
            }
        }
 public MsmqIntegrationInputChannel(MsmqIntegrationChannelListener listener)
     : base(listener, new MsmqIntegrationMessagePool(MsmqDefaults.MaxPoolSize))
 {
 }