Пример #1
0
                public Task MutateOutgoing(MutateOutgoingTransportMessageContext context)
                {
                    Assert.IsNotEmpty(context.OutgoingHeaders);
                    Assert.IsNotNull(context.OutgoingBody);
                    IReadOnlyDictionary <string, string> incomingHeaders;

                    context.TryGetIncomingHeaders(out incomingHeaders);
                    object incomingmessage;

                    context.TryGetIncomingMessage(out incomingmessage);
                    Assert.IsNotEmpty(incomingHeaders);
                    Assert.IsNotNull(incomingmessage);
                    return(Task.FromResult(0));
                }
        public Task MutateOutgoing(MutateOutgoingTransportMessageContext context)
        {
            object incomingMessage;

            if (context.TryGetIncomingMessage(out incomingMessage))
            {
                // do something with the incoming message
            }

            IReadOnlyDictionary <string, string> incomingHeaders;

            if (context.TryGetIncomingHeaders(out incomingHeaders))
            {
                // do something with the incoming headers
            }

            // the outgoing message
            var outgoingMessage = context.OutgoingMessage;

            // the bytes containing the serialized outgoing messages.
            var bytes = context.OutgoingBody;

            // optionally replace the Body.
            // this can be done using any information from the context
            context.OutgoingBody = ServiceThatChangesBody.Mutate(context.OutgoingMessage);


            // the outgoing headers
            IDictionary <string, string> headers = context.OutgoingHeaders;

            // optional manipulate headers

            // add a header
            headers.Add("MyHeaderKey1", "MyHeaderValue");

            // remove a header
            headers.Remove("MyHeaderKey2");

            return(Task.FromResult(0));
        }