Exemplo n.º 1
0
        public void Serialize <T>(Stream stream, ISendContext <T> context)
            where T : class
        {
            try
            {
                context.SetContentType(ContentTypeHeaderValue);

                XmlMessageEnvelope envelope = XmlMessageEnvelope.Create(context);

                _serializer.Serialize(stream, envelope, (declaringType, propertyType, value) =>
                {
                    if (declaringType == typeof(XmlMessageEnvelope) && propertyType == typeof(object))
                    {
                        return(typeof(T));
                    }

                    if (propertyType == typeof(object))
                    {
                        return(value.GetType());
                    }

                    return(propertyType);
                });
            }
            catch (SerializationException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new SerializationException("Failed to serialize message", ex);
            }
        }
Exemplo n.º 2
0
        public void Serialize <T>(Stream stream, T message)
        {
            try
            {
                var envelope = XmlMessageEnvelope.Create(message);

                _serializer.Serialize(stream, envelope, (declaringType, propertyType, value) =>
                {
                    if (declaringType == typeof(XmlMessageEnvelope) && propertyType == typeof(object))
                    {
                        return(typeof(T));
                    }

                    if (propertyType == typeof(object))
                    {
                        return(value.GetType());
                    }

                    return(propertyType);
                });
            }
            catch (SerializationException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new SerializationException("Failed to serialize message", ex);
            }
        }
        public void Serialize <T>(Stream output, T message)
        {
            CheckConvention.EnsureSerializable(message);
            var envelope = XmlMessageEnvelope.Create(message);

            GetSerializerFor <T>().Serialize(output, envelope);
        }
Exemplo n.º 4
0
        public static XmlMessageEnvelope Create <T>(ISendContext <T> context)
            where T : class
        {
            var envelope = new XmlMessageEnvelope(typeof(T), context.Message);

            envelope.SetUsingContext(context);

            return(envelope);
        }
Exemplo n.º 5
0
 public static void SetUsingContext(this XmlMessageEnvelope envelope, ISendContext headers)
 {
     envelope.RequestId          = headers.RequestId;
     envelope.ConversationId     = headers.ConversationId;
     envelope.CorrelationId      = headers.CorrelationId;
     envelope.SourceAddress      = headers.SourceAddress.ToStringOrNull() ?? envelope.SourceAddress;
     envelope.DestinationAddress = headers.DestinationAddress.ToStringOrNull() ?? envelope.DestinationAddress;
     envelope.ResponseAddress    = headers.ResponseAddress.ToStringOrNull() ?? envelope.ResponseAddress;
     envelope.FaultAddress       = headers.FaultAddress.ToStringOrNull() ?? envelope.FaultAddress;
     envelope.Network            = headers.Network;
     envelope.RetryCount         = headers.RetryCount;
     envelope.MessageType        = headers.MessageType ?? envelope.MessageType;
     if (headers.ExpirationTime.HasValue)
     {
         envelope.ExpirationTime = headers.ExpirationTime.Value;
     }
 }
Exemplo n.º 6
0
 public static void SetUsingMessageEnvelope(this IReceiveContext context, XmlMessageEnvelope envelope)
 {
     context.SetRequestId(envelope.RequestId);
     context.SetConversationId(envelope.ConversationId);
     context.SetCorrelationId(envelope.CorrelationId);
     context.SetSourceAddress(envelope.SourceAddress.ToUriOrNull());
     context.SetDestinationAddress(envelope.DestinationAddress.ToUriOrNull());
     context.SetResponseAddress(envelope.ResponseAddress.ToUriOrNull());
     context.SetFaultAddress(envelope.FaultAddress.ToUriOrNull());
     context.SetNetwork(envelope.Network);
     context.SetRetryCount(envelope.RetryCount);
     context.SetMessageType(envelope.MessageType);
     if (envelope.ExpirationTime.HasValue)
     {
         context.SetExpirationTime(envelope.ExpirationTime.Value);
     }
 }
Exemplo n.º 7
0
        public object Deserialize(Stream stream)
        {
            object message = _serializer.Deserialize(stream);

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

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

                InboundMessageHeaders.SetCurrent(envelope.GetMessageHeadersSetAction());

                return(envelope.Message);
            }

            return(message);
        }
Exemplo n.º 8
0
        public void Serialize <T>(Stream stream, T message)
        {
            var envelope = XmlMessageEnvelope.Create(message);

            _serializer.Serialize(stream, envelope);
        }