Beispiel #1
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();
                }
            }
        }
Beispiel #2
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 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();
                }
            }
        }
Beispiel #4
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 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();
                }
            }
        }
        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);
        }
Beispiel #7
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);
                    }
                }
            }
            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);
                    }
                }
            }
Beispiel #9
0
 public static bool TryGet(Message message, out CorrelationCallbackMessageProperty property)
 {
     if (message == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("message");
     }
     return(TryGet(message.Properties, out property));
 }
 public static bool TryGet(Message message, out CorrelationCallbackMessageProperty property)
 {
     if (message == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("message");
     }
     return TryGet(message.Properties, out property);
 }
 public static void AddOutgoingCorrelationCallbackData(CorrelationCallbackMessageProperty callback, Message message, bool client)
 {
     if (client)
     {
         callback.AddData(CorrelationName, () => GetCallbackContextCorrelationData(message));
     }
     else
     {
         callback.AddData(CorrelationName, () => GetContextCorrelationData(message));
     }
 }
 public static void AddOutgoingCorrelationCallbackData(CorrelationCallbackMessageProperty callback, Message message, bool client)
 {
     if (client)
     {
         callback.AddData(CorrelationName, () => GetCallbackContextCorrelationData(message));
     }
     else
     {
         callback.AddData(CorrelationName, () => GetContextCorrelationData(message));
     }
 }
 protected CorrelationCallbackMessageProperty(CorrelationCallbackMessageProperty callback)
 {
     if (callback == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("callback");
     }
     if (callback.data != null)
     {
         this.data = (CorrelationDataMessageProperty) callback.data.CreateCopy();
     }
     if ((callback.neededData != null) && (callback.neededData.Count > 0))
     {
         this.neededData = new List<string>(callback.neededData);
     }
 }
 protected CorrelationCallbackMessageProperty(CorrelationCallbackMessageProperty callback)
 {
     if (callback == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("callback");
     }
     if (callback.data != null)
     {
         this.data = (CorrelationDataMessageProperty)callback.data.CreateCopy();
     }
     if ((callback.neededData != null) && (callback.neededData.Count > 0))
     {
         this.neededData = new List <string>(callback.neededData);
     }
 }
        public static bool TryGet(MessageProperties properties, out CorrelationCallbackMessageProperty property)
        {
            if (properties == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("properties");
            }

            object value = null;
            if (properties.TryGetValue(PropertyName, out value))
            {
                property = value as CorrelationCallbackMessageProperty;
            }
            else
            {
                property = null;
            }
            return property != null;
        }
        public static bool TryGet(MessageProperties properties, out CorrelationCallbackMessageProperty property)
        {
            if (properties == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("properties");
            }
            object obj2 = null;

            if (properties.TryGetValue("CorrelationCallbackMessageProperty", out obj2))
            {
                property = obj2 as CorrelationCallbackMessageProperty;
            }
            else
            {
                property = null;
            }
            return(property != null);
        }
 public static void AddOutgoingCorrelationCallbackData(CorrelationCallbackMessageProperty callback, Message message, bool client)
 {
     Func<string> func = null;
     Func<string> func2 = null;
     if (client)
     {
         if (func == null)
         {
             func = () => GetCallbackContextCorrelationData(message);
         }
         callback.AddData(CorrelationName, func);
     }
     else
     {
         if (func2 == null)
         {
             func2 = () => GetContextCorrelationData(message);
         }
         callback.AddData(CorrelationName, func2);
     }
 }
Beispiel #18
0
        public static void AddOutgoingCorrelationCallbackData(CorrelationCallbackMessageProperty callback, Message message, bool client)
        {
            Func <string> func  = null;
            Func <string> func2 = null;

            if (client)
            {
                if (func == null)
                {
                    func = () => GetCallbackContextCorrelationData(message);
                }
                callback.AddData(CorrelationName, func);
            }
            else
            {
                if (func2 == null)
                {
                    func2 = () => GetContextCorrelationData(message);
                }
                callback.AddData(CorrelationName, func2);
            }
        }
        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);
        }
        internal MessageRpc(RequestContext requestContext, Message request, DispatchOperationRuntime operation,
            ServiceChannel channel, ServiceHostBase host, ChannelHandler channelHandler, bool cleanThread,
            OperationContext operationContext, InstanceContext instanceContext, EventTraceActivity eventTraceActivity)
        {
            Fx.Assert((operationContext != null), "System.ServiceModel.Dispatcher.MessageRpc.MessageRpc(), operationContext == null");
            Fx.Assert(channelHandler != null, "System.ServiceModel.Dispatcher.MessageRpc.MessageRpc(), channelHandler == null");

            this.Activity = null;
            this.EventTraceActivity = eventTraceActivity;            
            this.AsyncResult = null;
            this.CanSendReply = true;
            this.Channel = channel;
            this.channelHandler = channelHandler;
            this.Correlation = EmptyArray.Allocate(operation.Parent.CorrelationCount);
            this.CorrelationCallback = null;
            this.DidDeserializeRequestBody = false;
            this.TransactionMessageProperty = null;
            this.TransactedBatchContext = null;
            this.Error = null;
            this.ErrorProcessor = null;
            this.FaultInfo = new ErrorHandlerFaultInfo(request.Version.Addressing.DefaultFaultAction);
            this.HasSecurityContext = false;
            this.Host = host;
            this.Instance = null;
            this.MessageRpcOwnsInstanceContextThrottle = false;
            this.NextProcessor = null;
            this.NotUnderstoodHeaders = null;
            this.Operation = operation;
            this.OperationContext = operationContext;
            this.paused = false;
            this.ParametersDisposed = false;
            this.ReceiveContext = null;
            this.Request = request;
            this.RequestContext = requestContext;
            this.RequestContextThrewOnReply = false;
            this.SuccessfullySendReply = false;
            this.RequestVersion = request.Version;
            this.Reply = null;
            this.ReplyTimeoutHelper = new TimeoutHelper();
            this.SecurityContext = null;
            this.InstanceContext = instanceContext;
            this.SuccessfullyBoundInstance = false;
            this.SuccessfullyIncrementedActivity = false;
            this.SuccessfullyLockedInstance = false;
            this.switchedThreads = !cleanThread;
            this.transaction = null;
            this.InputParameters = null;
            this.OutputParameters = null;
            this.ReturnParameter = null;
            this.isInstanceContextSingleton = InstanceContextProviderBase.IsProviderSingleton(this.Channel.DispatchRuntime.InstanceContextProvider);
            this.invokeContinueGate = null;

            if (!operation.IsOneWay && !operation.Parent.ManualAddressing)
            {
                this.RequestID = request.Headers.MessageId;
                this.ReplyToInfo = new RequestReplyCorrelator.ReplyToInfo(request);
            }
            else
            {
                this.RequestID = null;
                this.ReplyToInfo = new RequestReplyCorrelator.ReplyToInfo();
            }

            this.HostingProperty = AspNetEnvironment.Current.GetHostingProperty(request, true);

            if (DiagnosticUtility.ShouldUseActivity)
            {
                this.Activity = TraceUtility.ExtractActivity(this.Request);
            }

            if (DiagnosticUtility.ShouldUseActivity || TraceUtility.ShouldPropagateActivity)
            {
                this.ResponseActivityId = ActivityIdHeader.ExtractActivityId(this.Request);
            }
            else
            {
                this.ResponseActivityId = Guid.Empty;
            }

            this.InvokeNotification = new MessageRpcInvokeNotification(this.Activity, this.channelHandler);

            if (this.EventTraceActivity == null && FxTrace.Trace.IsEnd2EndActivityTracingEnabled)
            {
                if (this.Request != null)
                {
                    this.EventTraceActivity = EventTraceActivityHelper.TryExtractActivity(this.Request, true);
                }
            }
        }
 // This constructor should be used when creating the RPCCorrelationMessageproperty the first time
 // Here we copy the data & the needed data from the original callback
 public RpcCorrelationCallbackMessageProperty(CorrelationCallbackMessageProperty innerCallback,
     ImmutableDispatchRuntime runtime, ref MessageRpc rpc)
     : base(innerCallback)
 {
     this.innerCallback = innerCallback;
     this.runtime = runtime;
     this.rpc = rpc;
 }
 // This constructor should be used when we are making a copy from the already initialized RPCCorrelationCallbackMessageProperty
 public RpcCorrelationCallbackMessageProperty(RpcCorrelationCallbackMessageProperty rpcCallbackMessageProperty)
     : base(rpcCallbackMessageProperty)
 {
     this.innerCallback = rpcCallbackMessageProperty.innerCallback;
     this.runtime = rpcCallbackMessageProperty.runtime;
     this.rpc = rpcCallbackMessageProperty.rpc;
 }
 public RpcCorrelationCallbackMessageProperty(ImmutableDispatchRuntime.RpcCorrelationCallbackMessageProperty rpcCallbackMessageProperty) : base(rpcCallbackMessageProperty)
 {
     this.innerCallback = rpcCallbackMessageProperty.innerCallback;
     this.runtime = rpcCallbackMessageProperty.runtime;
     this.rpc = rpcCallbackMessageProperty.rpc;
 }