public virtual IMessageCtrl AsyncProcessMessage(IMessage reqMsg, IMessageSink replySink)
        {
            IMessage     message = InternalSink.ValidateMessage(reqMsg);
            IMessageCtrl result  = null;

            if (message == null)
            {
                message = InternalSink.DisallowAsyncActivation(reqMsg);
            }
            if (message != null)
            {
                if (replySink != null)
                {
                    replySink.SyncProcessMessage(message);
                }
            }
            else
            {
                if (RemotingServices.CORProfilerTrackRemotingAsync())
                {
                    Guid guid;
                    RemotingServices.CORProfilerRemotingClientSendingMessage(out guid, true);
                    if (RemotingServices.CORProfilerTrackRemotingCookie())
                    {
                        reqMsg.Properties["CORProfilerCookie"] = guid;
                    }
                    if (replySink != null)
                    {
                        IMessageSink messageSink = new ClientAsyncReplyTerminatorSink(replySink);
                        replySink = messageSink;
                    }
                }
                Context currentContext = Thread.CurrentContext;
                currentContext.NotifyDynamicSinks(reqMsg, true, true, true, true);
                if (replySink != null)
                {
                    replySink = new AsyncReplySink(replySink, currentContext);
                }
                object[] array = new object[3];
                InternalCrossContextDelegate internalCrossContextDelegate = new InternalCrossContextDelegate(ClientContextTerminatorSink.AsyncProcessMessageCallback);
                IMessageSink channelSink = this.GetChannelSink(reqMsg);
                array[0] = reqMsg;
                array[1] = replySink;
                array[2] = channelSink;
                if (channelSink != CrossContextChannel.MessageSink)
                {
                    result = (IMessageCtrl)Thread.CurrentThread.InternalCrossContextCallback(Context.DefaultContext, internalCrossContextDelegate, array);
                }
                else
                {
                    result = (IMessageCtrl)internalCrossContextDelegate(array);
                }
            }
            return(result);
        }
        public virtual IMessageCtrl AsyncProcessMessage(IMessage reqMsg, IMessageSink replySink)
        {
            IMessage     msg  = InternalSink.ValidateMessage(reqMsg);
            IMessageCtrl ctrl = null;

            if (msg == null)
            {
                msg = InternalSink.DisallowAsyncActivation(reqMsg);
            }
            if (msg != null)
            {
                if (replySink != null)
                {
                    replySink.SyncProcessMessage(msg);
                }
                return(ctrl);
            }
            if (RemotingServices.CORProfilerTrackRemotingAsync())
            {
                Guid guid;
                RemotingServices.CORProfilerRemotingClientSendingMessage(out guid, true);
                if (RemotingServices.CORProfilerTrackRemotingCookie())
                {
                    reqMsg.Properties["CORProfilerCookie"] = guid;
                }
                if (replySink != null)
                {
                    IMessageSink sink = new ClientAsyncReplyTerminatorSink(replySink);
                    replySink = sink;
                }
            }
            Context currentContext = Thread.CurrentContext;

            currentContext.NotifyDynamicSinks(reqMsg, true, true, true, true);
            if (replySink != null)
            {
                replySink = new System.Runtime.Remoting.Messaging.AsyncReplySink(replySink, currentContext);
            }
            object[] args = new object[3];
            InternalCrossContextDelegate ftnToCall = new InternalCrossContextDelegate(ClientContextTerminatorSink.AsyncProcessMessageCallback);
            IMessageSink channelSink = this.GetChannelSink(reqMsg);

            args[0] = reqMsg;
            args[1] = replySink;
            args[2] = channelSink;
            if (channelSink != CrossContextChannel.MessageSink)
            {
                return((IMessageCtrl)Thread.CurrentThread.InternalCrossContextCallback(Context.DefaultContext, ftnToCall, args));
            }
            return((IMessageCtrl)ftnToCall(args));
        }
예제 #3
0
        public virtual IMessageCtrl AsyncProcessMessage(IMessage reqMsg, IMessageSink replySink) 
        {
            Message.DebugOut("+++++++++++++++++++++++++ CliCtxTerminator: AsyncProcessMsg");
            IMessage errMsg = ValidateMessage(reqMsg);
            IMessageCtrl msgCtrl=null;
            if (errMsg == null)
            {
                errMsg = DisallowAsyncActivation(reqMsg);
            }

            if (errMsg != null)
            {
                if (replySink != null)
                {
                    replySink.SyncProcessMessage(errMsg);
                }
            }
            else
            {   
                // If active, notify the profiler that an asynchronous remoting call is being made.
                if (RemotingServices.CORProfilerTrackRemotingAsync())
                {
                    Guid g;

                    RemotingServices.CORProfilerRemotingClientSendingMessage(out g, true);

                    if (RemotingServices.CORProfilerTrackRemotingCookie())
                        reqMsg.Properties["CORProfilerCookie"] = g;

                    // Only wrap the replySink if the call wants a reply
                    if (replySink != null)
                    {
                        // Now wrap the reply sink in our own so that we can notify the profiler of
                        // when the reply is received.  Upon invocation, it will notify the profiler
                        // then pass control on to the replySink passed in above.
                        IMessageSink profSink = new ClientAsyncReplyTerminatorSink(replySink);
    
                        // Replace the reply sink with our own
                        replySink = profSink;
                    }
                }

                Context cliCtx = Thread.CurrentContext;

                // Notify dynamic sinks that an Async call started
                cliCtx.NotifyDynamicSinks(
                        reqMsg, 
                        true,   // bCliSide
                        true,   // bStart
                        true,   // bAsync
                        true);  // bNotifyGlobals                           

                // Intercept the async reply to force the thread back
                // into the client-context before it executes further
                // and to notify dynamic sinks
                if (replySink != null)
                {
                    replySink = new AsyncReplySink(replySink, cliCtx); 
                }

                // Forward call to the channel.
                IMessageSink channelSink = GetChannelSink(reqMsg);
                // Move to default context unless we are going through
                // the cross-context channel
                ContextTransitionFrame frame = new ContextTransitionFrame();
                if (channelSink != CrossContextChannel.MessageSink)
                {
                    Thread.CurrentThread.EnterContext(
                        Context.DefaultContext,
                        ref frame);
                }
                msgCtrl = channelSink.AsyncProcessMessage(reqMsg, replySink);

                if (channelSink != CrossContextChannel.MessageSink)
                {
                    Thread.CurrentThread.ReturnToContext(ref frame);
                }
            }
            return msgCtrl;
        }
        [System.Security.SecurityCritical]  // auto-generated
        public virtual IMessageCtrl AsyncProcessMessage(IMessage reqMsg, IMessageSink replySink)
        {
            Message.DebugOut("+++++++++++++++++++++++++ CliCtxTerminator: AsyncProcessMsg");
            IMessage     errMsg  = ValidateMessage(reqMsg);
            IMessageCtrl msgCtrl = null;

            if (errMsg == null)
            {
                errMsg = DisallowAsyncActivation(reqMsg);
            }

            if (errMsg != null)
            {
                if (replySink != null)
                {
                    replySink.SyncProcessMessage(errMsg);
                }
            }
            else
            {
                // If active, notify the profiler that an asynchronous remoting call is being made.
                if (RemotingServices.CORProfilerTrackRemotingAsync())
                {
                    Guid g;

                    RemotingServices.CORProfilerRemotingClientSendingMessage(out g, true);

                    if (RemotingServices.CORProfilerTrackRemotingCookie())
                    {
                        reqMsg.Properties["CORProfilerCookie"] = g;
                    }

                    // Only wrap the replySink if the call wants a reply
                    if (replySink != null)
                    {
                        // Now wrap the reply sink in our own so that we can notify the profiler of
                        // when the reply is received.  Upon invocation, it will notify the profiler
                        // then pass control on to the replySink passed in above.
                        IMessageSink profSink = new ClientAsyncReplyTerminatorSink(replySink);

                        // Replace the reply sink with our own
                        replySink = profSink;
                    }
                }

                Context cliCtx = Thread.CurrentContext;

                // Notify dynamic sinks that an Async call started
                cliCtx.NotifyDynamicSinks(
                    reqMsg,
                    true,       // bCliSide
                    true,       // bStart
                    true,       // bAsync
                    true);      // bNotifyGlobals

                // Intercept the async reply to force the thread back
                // into the client-context before it executes further
                // and to notify dynamic sinks
                if (replySink != null)
                {
                    replySink = new AsyncReplySink(replySink, cliCtx);
                }

                Object[] args = new Object[] { null, null, null };
                InternalCrossContextDelegate xctxDel = new InternalCrossContextDelegate(AsyncProcessMessageCallback);

                IMessageSink channelSink = GetChannelSink(reqMsg);

                // Forward call to the channel.
                args[0] = reqMsg;
                args[1] = replySink;
                args[2] = channelSink;

                // Move to default context unless we are going through
                // the cross-context channel
                if (channelSink != CrossContextChannel.MessageSink)
                {
                    msgCtrl = (IMessageCtrl)Thread.CurrentThread.InternalCrossContextCallback(Context.DefaultContext, xctxDel, args);
                }
                else
                {
                    msgCtrl = (IMessageCtrl)xctxDel(args);
                }
            }
            return(msgCtrl);
        }