public Message Request(Message message, TimeSpan timeout)
        {
            CorrelationCallbackMessageProperty property = null;
            TimeoutHelper helper   = new TimeoutHelper(timeout);
            Message       message2 = message;

            this.contextProtocol.OnOutgoingMessage(message, null);
            if ((message != null) && CorrelationCallbackMessageProperty.TryGet(message, out property))
            {
                ContextExchangeCorrelationHelper.AddOutgoingCorrelationCallbackData(property, message, true);
                if (property.IsFullyDefined)
                {
                    message2 = property.FinalizeCorrelation(message, helper.RemainingTime());
                }
            }
            Message message3 = null;

            try
            {
                message3 = base.InnerChannel.Request(message2, timeout);
                if (message3 != null)
                {
                    this.contextProtocol.OnIncomingMessage(message3);
                }
            }
            finally
            {
                if ((message != null) && !object.ReferenceEquals(message, message2))
                {
                    message2.Close();
                }
            }
            return(message3);
        }
        public override void OnIncomingMessage(Message message)
        {
            if (message == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("message");
            }

            if (this.ContextExchangeMechanism == ContextExchangeMechanism.HttpCookie)
            {
                this.OnReceiveHttpCookies(message);
            }
            else
            {
                this.OnReceiveSoapContextHeader(message);
            }

            // deserialize the callback context header, if present
            int headerIndex = message.Headers.FindHeader(CallbackContextMessageHeader.CallbackContextHeaderName, CallbackContextMessageHeader.CallbackContextHeaderNamespace);

            if (headerIndex > 0)
            {
                CallbackContextMessageProperty property = CallbackContextMessageHeader.ParseCallbackContextHeader(message.Headers.GetReaderAtHeader(headerIndex), message.Version.Addressing);
                message.Properties.Add(CallbackContextMessageProperty.Name, property);
            }

            ContextExchangeCorrelationHelper.AddIncomingContextCorrelationData(message);
        }
Example #3
0
        public void Send(Message message, TimeSpan timeout)
        {
            CorrelationCallbackMessageProperty property = null;
            TimeoutHelper helper   = new TimeoutHelper(timeout);
            Message       message2 = message;

            if (message != null)
            {
                this.ContextProtocol.OnOutgoingMessage(message, null);
                if (CorrelationCallbackMessageProperty.TryGet(message, out property))
                {
                    ContextExchangeCorrelationHelper.AddOutgoingCorrelationCallbackData(property, message, this.IsClient);
                    if (property.IsFullyDefined)
                    {
                        message2 = property.FinalizeCorrelation(message, helper.RemainingTime());
                    }
                }
            }
            try
            {
                base.InnerChannel.Send(message2, helper.RemainingTime());
            }
            finally
            {
                if ((message != null) && !object.ReferenceEquals(message, message2))
                {
                    message2.Close();
                }
            }
        }
            public RequestAsyncResult(Message message, IRequestChannel channel, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state)
            {
                this.channel       = channel;
                this.message       = this.requestMessage = message;
                this.timeoutHelper = new TimeoutHelper(timeout);
                bool flag = true;

                if ((message != null) && CorrelationCallbackMessageProperty.TryGet(message, out this.correlationCallback))
                {
                    ContextExchangeCorrelationHelper.AddOutgoingCorrelationCallbackData(this.correlationCallback, message, true);
                    if (this.correlationCallback.IsFullyDefined)
                    {
                        IAsyncResult result = this.correlationCallback.BeginFinalizeCorrelation(this.message, this.timeoutHelper.RemainingTime(), ContextRequestChannelBase <TChannel> .RequestAsyncResult.onFinalizeCorrelation, this);
                        if (result.CompletedSynchronously && this.OnFinalizeCorrelationCompleted(result))
                        {
                            base.Complete(true);
                        }
                        flag = false;
                    }
                }
                if (flag)
                {
                    IAsyncResult result2 = this.channel.BeginRequest(this.message, this.timeoutHelper.RemainingTime(), ContextRequestChannelBase <TChannel> .RequestAsyncResult.onRequest, this);
                    if (result2.CompletedSynchronously)
                    {
                        this.OnRequestCompleted(result2);
                        base.Complete(true);
                    }
                }
            }
        public override void Reply(Message message, TimeSpan timeout)
        {
            TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);
            Message       replyMessage  = message;

            if (message != null)
            {
                this.contextProtocol.OnOutgoingMessage(message, this);

                CorrelationCallbackMessageProperty callback;
                if (CorrelationCallbackMessageProperty.TryGet(message, out callback))
                {
                    ContextExchangeCorrelationHelper.AddOutgoingCorrelationCallbackData(callback, message, false);

                    if (callback.IsFullyDefined)
                    {
                        replyMessage = callback.FinalizeCorrelation(message, timeoutHelper.RemainingTime());
                        // we are done finalizing correlation, removing the messageproperty since we do not need it anymore
                        replyMessage.Properties.Remove(CorrelationCallbackMessageProperty.Name);
                    }
                }
            }

            try
            {
                this.innerContext.Reply(replyMessage, timeoutHelper.RemainingTime());
            }
            finally
            {
                if (message != null && !object.ReferenceEquals(message, replyMessage))
                {
                    replyMessage.Close();
                }
            }
        }
Example #6
0
            public SendAsyncResult(Message message, ContextOutputChannelBase <TChannel> channel, ContextProtocol contextProtocol, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state)
            {
                this.channel       = channel;
                this.message       = this.sendMessage = message;
                this.timeoutHelper = new TimeoutHelper(timeout);
                bool flag = true;

                if (message != null)
                {
                    contextProtocol.OnOutgoingMessage(message, null);
                    if (CorrelationCallbackMessageProperty.TryGet(message, out this.correlationCallback))
                    {
                        ContextExchangeCorrelationHelper.AddOutgoingCorrelationCallbackData(this.correlationCallback, message, this.channel.IsClient);
                        if (this.correlationCallback.IsFullyDefined)
                        {
                            IAsyncResult result = this.correlationCallback.BeginFinalizeCorrelation(this.message, this.timeoutHelper.RemainingTime(), ContextOutputChannelBase <TChannel> .SendAsyncResult.onFinalizeCorrelation, this);
                            if (result.CompletedSynchronously && this.OnFinalizeCorrelationCompleted(result))
                            {
                                base.Complete(true);
                            }
                            flag = false;
                        }
                    }
                }
                if (flag)
                {
                    IAsyncResult result2 = this.channel.InnerChannel.BeginSend(this.message, this.timeoutHelper.RemainingTime(), ContextOutputChannelBase <TChannel> .SendAsyncResult.onSend, this);
                    if (result2.CompletedSynchronously)
                    {
                        this.OnSendCompleted(result2);
                        base.Complete(true);
                    }
                }
            }
Example #7
0
        public override void Reply(Message message, TimeSpan timeout)
        {
            TimeoutHelper helper   = new TimeoutHelper(timeout);
            Message       message2 = message;

            if (message != null)
            {
                CorrelationCallbackMessageProperty property;
                this.contextProtocol.OnOutgoingMessage(message, this);
                if (CorrelationCallbackMessageProperty.TryGet(message, out property))
                {
                    ContextExchangeCorrelationHelper.AddOutgoingCorrelationCallbackData(property, message, false);
                    if (property.IsFullyDefined)
                    {
                        message2 = property.FinalizeCorrelation(message, helper.RemainingTime());
                        message2.Properties.Remove(CorrelationCallbackMessageProperty.Name);
                    }
                }
            }
            try
            {
                this.innerContext.Reply(message2, helper.RemainingTime());
            }
            finally
            {
                if ((message != null) && !object.ReferenceEquals(message, message2))
                {
                    message2.Close();
                }
            }
        }
Example #8
0
            public ReplyAsyncResult(Message message, ContextChannelRequestContext context, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state)
            {
                this.context       = context;
                this.message       = this.replyMessage = message;
                this.timeoutHelper = new TimeoutHelper(timeout);
                bool flag = true;

                if (message != null)
                {
                    this.context.contextProtocol.OnOutgoingMessage(message, this.context);
                    if (CorrelationCallbackMessageProperty.TryGet(message, out this.correlationCallback))
                    {
                        ContextExchangeCorrelationHelper.AddOutgoingCorrelationCallbackData(this.correlationCallback, message, false);
                        if (this.correlationCallback.IsFullyDefined)
                        {
                            IAsyncResult result = this.correlationCallback.BeginFinalizeCorrelation(this.message, this.timeoutHelper.RemainingTime(), onFinalizeCorrelation, this);
                            if (result.CompletedSynchronously && this.OnFinalizeCorrelationCompleted(result))
                            {
                                base.Complete(true);
                            }
                            flag = false;
                        }
                    }
                }
                if (flag)
                {
                    IAsyncResult result2 = this.context.innerContext.BeginReply(this.message, this.timeoutHelper.RemainingTime(), onReply, this);
                    if (result2.CompletedSynchronously)
                    {
                        this.OnReplyCompleted(result2);
                        base.Complete(true);
                    }
                }
            }
        public void Send(Message message, TimeSpan timeout)
        {
            CorrelationCallbackMessageProperty callback = null;
            TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);
            Message       sendMessage   = message;

            if (message != null)
            {
                this.ContextProtocol.OnOutgoingMessage(message, null);
                if (CorrelationCallbackMessageProperty.TryGet(message, out callback))
                {
                    ContextExchangeCorrelationHelper.AddOutgoingCorrelationCallbackData(callback, message, this.IsClient);
                    if (callback.IsFullyDefined)
                    {
                        sendMessage = callback.FinalizeCorrelation(message, timeoutHelper.RemainingTime());
                    }
                }
            }

            try
            {
                this.InnerChannel.Send(sendMessage, timeoutHelper.RemainingTime());
            }
            finally
            {
                if (message != null && !object.ReferenceEquals(message, sendMessage))
                {
                    sendMessage.Close();
                }
            }
        }
Example #10
0
        public override void OnIncomingMessage(Message message)
        {
            if (message == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("message");
            }
            if (base.ContextExchangeMechanism == ContextExchangeMechanism.HttpCookie)
            {
                this.OnReceiveHttpCookies(message);
            }
            else
            {
                this.OnReceiveSoapContextHeader(message);
            }
            int headerIndex = message.Headers.FindHeader("CallbackContext", "http://schemas.microsoft.com/ws/2008/02/context");

            if (headerIndex > 0)
            {
                CallbackContextMessageProperty property = CallbackContextMessageHeader.ParseCallbackContextHeader(message.Headers.GetReaderAtHeader(headerIndex), message.Version.Addressing);
                message.Properties.Add(CallbackContextMessageProperty.Name, property);
            }
            ContextExchangeCorrelationHelper.AddIncomingContextCorrelationData(message);
        }
        public Message Request(Message message, TimeSpan timeout)
        {
            CorrelationCallbackMessageProperty callback = null;
            TimeoutHelper timeoutHelper  = new TimeoutHelper(timeout);
            Message       requestMessage = message;

            this.contextProtocol.OnOutgoingMessage(message, null);
            if (message != null && CorrelationCallbackMessageProperty.TryGet(message, out callback))
            {
                ContextExchangeCorrelationHelper.AddOutgoingCorrelationCallbackData(callback, message, true);
                if (callback.IsFullyDefined)
                {
                    requestMessage = callback.FinalizeCorrelation(message, timeoutHelper.RemainingTime());
                }
            }

            Message response = null;

            try
            {
                response = this.InnerChannel.Request(requestMessage, timeout);
                if (response != null)
                {
                    this.contextProtocol.OnIncomingMessage(response);
                }
            }
            finally
            {
                if (message != null && !object.ReferenceEquals(message, requestMessage))
                {
                    requestMessage.Close();
                }
            }

            return(response);
        }