Beispiel #1
0
        public object Deserialize(Stream stream)
        {
            try
            {
                object message = _serializer.Deserialize(stream);

                if (message == null)
                {
                    throw new SerializationException("Could not deserialize message.");
                }

                if (message is XmlMessageEnvelope)
                {
                    var envelope = message as XmlMessageEnvelope;

                    InboundMessageHeaders.SetCurrent(envelope.GetMessageHeadersSetAction());

                    return(envelope.Message);
                }

                return(message);
            }
            catch (SerializationException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new SerializationException("Failed to serialize message", ex);
            }
        }
        public object Deserialize(Stream input)
        {
            object obj = GetDeserializerFor(typeof(XmlReceiveMessageEnvelope)).Deserialize(input);

            if (obj.GetType() != typeof(XmlReceiveMessageEnvelope))
            {
                throw new SerializationException("An unknown message type was received: " + obj.GetType().FullName);
            }

            XmlReceiveMessageEnvelope envelope = (XmlReceiveMessageEnvelope)obj;

            if (string.IsNullOrEmpty(envelope.MessageType))
            {
                throw new SerializationException("No message type found on envelope");
            }

            Type t = Type.GetType(envelope.MessageType, true, true);

            using (var reader = new XmlNodeReader(envelope.Message))
            {
                obj = GetDeserializerFor(t).Deserialize(reader);
            }

            InboundMessageHeaders.SetCurrent(envelope.GetMessageHeadersSetAction());

            return(obj);
        }
        private static object DeserializeHeaderHandler(Header[] headers)
        {
            if (headers == null)
            {
                return(null);
            }

            InboundMessageHeaders.SetCurrent(context =>
            {
                context.Reset();

                for (int i = 0; i < headers.Length; i++)
                {
                    MapNameValuePair(context, headers[i]);
                }
            });

            return(null);
        }
Beispiel #4
0
 private static void RewriteResponseAddress(Uri responseAddress)
 {
     InboundMessageHeaders.SetCurrent(x => x.SetResponseAddress(responseAddress));
 }