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

            if (message == null)
            {
                message = InternalSink.DisallowAsyncActivation(reqMsg);
            }
            if (message != null)
            {
                if (replySink != null)
                {
                    replySink.SyncProcessMessage(message);
                }
            }
            else
            {
                MarshalByRefObject marshalByRefObject;
                IMessageSink       objectChain = this.GetObjectChain(reqMsg, out marshalByRefObject);
                IDisposable        iDis;
                if (marshalByRefObject != null && (iDis = (marshalByRefObject as IDisposable)) != null)
                {
                    DisposeSink disposeSink = new DisposeSink(iDis, replySink);
                    replySink = disposeSink;
                }
                result = objectChain.AsyncProcessMessage(reqMsg, replySink);
            }
            return(result);
        }
Exemple #2
0
        public virtual IMessage SyncProcessMessage(IMessage reqMsg)
        {
            IMessage message = InternalSink.ValidateMessage(reqMsg);

            if (message != null)
            {
                return(message);
            }
            ServerIdentity serverIdentity         = InternalSink.GetServerIdentity(reqMsg);
            ArrayWithSize  serverSideDynamicSinks = serverIdentity.ServerSideDynamicSinks;

            if (serverSideDynamicSinks != null)
            {
                DynamicPropertyHolder.NotifyDynamicSinks(reqMsg, serverSideDynamicSinks, false, true, false);
            }
            IMessageSink messageSink = this._stackBuilderSink.ServerObject as IMessageSink;
            IMessage     message2;

            if (messageSink != null)
            {
                message2 = messageSink.SyncProcessMessage(reqMsg);
            }
            else
            {
                message2 = this._stackBuilderSink.SyncProcessMessage(reqMsg);
            }
            if (serverSideDynamicSinks != null)
            {
                DynamicPropertyHolder.NotifyDynamicSinks(message2, serverSideDynamicSinks, false, false, false);
            }
            return(message2);
        }
Exemple #3
0
        public virtual IMessageCtrl AsyncProcessMessage(IMessage reqMsg, IMessageSink replySink)
        {
            IMessageCtrl result  = null;
            IMessage     message = InternalSink.ValidateMessage(reqMsg);

            if (message != null)
            {
                if (replySink != null)
                {
                    replySink.SyncProcessMessage(message);
                }
            }
            else
            {
                IMessageSink messageSink = this._stackBuilderSink.ServerObject as IMessageSink;
                if (messageSink != null)
                {
                    result = messageSink.AsyncProcessMessage(reqMsg, replySink);
                }
                else
                {
                    result = this._stackBuilderSink.AsyncProcessMessage(reqMsg, replySink);
                }
            }
            return(result);
        }
Exemple #4
0
        internal static ServerIdentity GetServerIdentity(IMessage reqMsg)
        {
            ServerIdentity   serverIdentity  = null;
            bool             flag            = false;
            IInternalMessage internalMessage = reqMsg as IInternalMessage;

            if (internalMessage != null)
            {
                serverIdentity = ((IInternalMessage)reqMsg).ServerIdentityObject;
                flag           = true;
            }
            else if (reqMsg is InternalMessageWrapper)
            {
                serverIdentity = (ServerIdentity)((InternalMessageWrapper)reqMsg).GetServerIdentityObject();
            }
            if (serverIdentity == null)
            {
                string   uri      = InternalSink.GetURI(reqMsg);
                Identity identity = IdentityHolder.ResolveIdentity(uri);
                if (identity is ServerIdentity)
                {
                    serverIdentity = (ServerIdentity)identity;
                    if (flag)
                    {
                        internalMessage.ServerIdentityObject = serverIdentity;
                    }
                }
            }
            return(serverIdentity);
        }
Exemple #5
0
        internal static Identity GetIdentity(IMessage reqMsg)
        {
            Identity identity = null;

            if (reqMsg is IInternalMessage)
            {
                identity = ((IInternalMessage)reqMsg).IdentityObject;
            }
            else if (reqMsg is InternalMessageWrapper)
            {
                identity = (Identity)((InternalMessageWrapper)reqMsg).GetIdentityObject();
            }
            if (identity == null)
            {
                string uri = InternalSink.GetURI(reqMsg);
                identity = IdentityHolder.ResolveIdentity(uri);
                if (identity == null)
                {
                    throw new ArgumentException(Environment.GetResourceString("Remoting_ServerObjectNotFound", new object[]
                    {
                        uri
                    }));
                }
            }
            return(identity);
        }
        public virtual IMessageCtrl AsyncProcessMessage(IMessage reqMsg, IMessageSink replySink)
        {
            IMessageCtrl       ctrl = null;
            MarshalByRefObject obj2;
            IDisposable        disposable;
            IMessage           msg = InternalSink.ValidateMessage(reqMsg);

            if (msg == null)
            {
                msg = InternalSink.DisallowAsyncActivation(reqMsg);
            }
            if (msg != null)
            {
                if (replySink != null)
                {
                    replySink.SyncProcessMessage(msg);
                }
                return(ctrl);
            }
            IMessageSink objectChain = this.GetObjectChain(reqMsg, out obj2);

            if ((obj2 != null) && ((disposable = obj2 as IDisposable) != null))
            {
                DisposeSink sink2 = new DisposeSink(disposable, replySink);
                replySink = sink2;
            }
            return(objectChain.AsyncProcessMessage(reqMsg, replySink));
        }
        public virtual IMessageCtrl AsyncProcessMessage(IMessage reqMsg, IMessageSink replySink)
        {
            IMessageCtrl messageCtrl = (IMessageCtrl)null;
            IMessage     msg1        = InternalSink.ValidateMessage(reqMsg) ?? InternalSink.DisallowAsyncActivation(reqMsg);

            if (msg1 != null)
            {
                if (replySink != null)
                {
                    replySink.SyncProcessMessage(msg1);
                }
            }
            else
            {
                MarshalByRefObject marshalByRefObject;
                IMessageSink       objectChain = this.GetObjectChain(reqMsg, out marshalByRefObject);
                IDisposable        iDis;
                if (marshalByRefObject != null && (iDis = marshalByRefObject as IDisposable) != null)
                {
                    replySink = (IMessageSink) new DisposeSink(iDis, replySink);
                }
                IMessage     msg2       = reqMsg;
                IMessageSink replySink1 = replySink;
                messageCtrl = objectChain.AsyncProcessMessage(msg2, replySink1);
            }
            return(messageCtrl);
        }
Exemple #8
0
        public virtual IMessage SyncProcessMessage(IMessage reqMsg)
        {
            IMessage message = InternalSink.ValidateMessage(reqMsg);

            if (message != null)
            {
                return(message);
            }
            return(Thread.CurrentContext.GetClientContextChain().SyncProcessMessage(reqMsg));
        }
        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 IMessage SyncProcessMessage(IMessage reqMsg)
        {
            IMessage message2;
            IMessage message = InternalSink.ValidateMessage(reqMsg);

            if (message != null)
            {
                return(message);
            }
            Context currentContext = Thread.CurrentContext;
            bool    flag           = currentContext.NotifyDynamicSinks(reqMsg, true, true, false, true);

            if (reqMsg is IConstructionCallMessage)
            {
                message = currentContext.NotifyActivatorProperties(reqMsg, false);
                if (message != null)
                {
                    return(message);
                }
                message2 = ((IConstructionCallMessage)reqMsg).Activator.Activate((IConstructionCallMessage)reqMsg);
                message  = currentContext.NotifyActivatorProperties(message2, false);
                if (message != null)
                {
                    return(message);
                }
            }
            else
            {
                message2 = null;
                ChannelServices.NotifyProfiler(reqMsg, RemotingProfilerEvent.ClientSend);
                object[]     args        = new object[2];
                IMessageSink channelSink = this.GetChannelSink(reqMsg);
                args[0] = reqMsg;
                args[1] = channelSink;
                InternalCrossContextDelegate ftnToCall = new InternalCrossContextDelegate(ClientContextTerminatorSink.SyncProcessMessageCallback);
                if (channelSink != CrossContextChannel.MessageSink)
                {
                    message2 = (IMessage)Thread.CurrentThread.InternalCrossContextCallback(Context.DefaultContext, ftnToCall, args);
                }
                else
                {
                    message2 = (IMessage)ftnToCall(args);
                }
                ChannelServices.NotifyProfiler(message2, RemotingProfilerEvent.ClientReceive);
            }
            if (flag)
            {
                currentContext.NotifyDynamicSinks(reqMsg, true, false, false, true);
            }
            return(message2);
        }
        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));
        }
Exemple #12
0
        public virtual IMessageCtrl AsyncProcessMessage(IMessage reqMsg, IMessageSink replySink)
        {
            IMessageCtrl ctrl = null;
            IMessage     msg  = InternalSink.ValidateMessage(reqMsg);

            if (msg != null)
            {
                if (replySink != null)
                {
                    replySink.SyncProcessMessage(msg);
                }
                return(ctrl);
            }
            return(Thread.CurrentContext.GetClientContextChain().AsyncProcessMessage(reqMsg, replySink));
        }
Exemple #13
0
        public virtual IMessageCtrl AsyncProcessMessage(IMessage reqMsg, IMessageSink replySink)
        {
            IMessageCtrl result  = null;
            IMessage     message = InternalSink.ValidateMessage(reqMsg);

            if (message != null)
            {
                if (replySink != null)
                {
                    replySink.SyncProcessMessage(message);
                }
            }
            else
            {
                result = Thread.CurrentContext.GetClientContextChain().AsyncProcessMessage(reqMsg, replySink);
            }
            return(result);
        }
        public virtual IMessageCtrl AsyncProcessMessage(IMessage reqMsg, IMessageSink replySink)
        {
            IMessageCtrl messageCtrl = (IMessageCtrl)null;
            IMessage     msg         = InternalSink.ValidateMessage(reqMsg);

            if (msg != null)
            {
                if (replySink != null)
                {
                    replySink.SyncProcessMessage(msg);
                }
            }
            else
            {
                IMessageSink messageSink = this._stackBuilderSink.ServerObject as IMessageSink;
                messageCtrl = messageSink == null?this._stackBuilderSink.AsyncProcessMessage(reqMsg, replySink) : messageSink.AsyncProcessMessage(reqMsg, replySink);
            }
            return(messageCtrl);
        }
Exemple #15
0
        public virtual IMessage SyncProcessMessage(IMessage reqMsg)
        {
            IMessage message = InternalSink.ValidateMessage(reqMsg);

            if (message != null)
            {
                return(message);
            }
            Context  currentContext = Thread.CurrentContext;
            IMessage message2;

            if (reqMsg is IConstructionCallMessage)
            {
                message = currentContext.NotifyActivatorProperties(reqMsg, true);
                if (message != null)
                {
                    return(message);
                }
                message2 = ((IConstructionCallMessage)reqMsg).Activator.Activate((IConstructionCallMessage)reqMsg);
                message  = currentContext.NotifyActivatorProperties(message2, true);
                if (message != null)
                {
                    return(message);
                }
            }
            else
            {
                MarshalByRefObject marshalByRefObject = null;
                try
                {
                    message2 = this.GetObjectChain(reqMsg, out marshalByRefObject).SyncProcessMessage(reqMsg);
                }
                finally
                {
                    IDisposable disposable;
                    if (marshalByRefObject != null && (disposable = (marshalByRefObject as IDisposable)) != null)
                    {
                        disposable.Dispose();
                    }
                }
            }
            return(message2);
        }
Exemple #16
0
        public virtual IMessageCtrl AsyncProcessMessage(IMessage reqMsg, IMessageSink replySink)
        {
            IMessageCtrl ctrl = null;
            IMessage     msg  = InternalSink.ValidateMessage(reqMsg);

            if (msg != null)
            {
                if (replySink != null)
                {
                    replySink.SyncProcessMessage(msg);
                }
                return(ctrl);
            }
            IMessageSink serverObject = this._stackBuilderSink.ServerObject as IMessageSink;

            if (serverObject != null)
            {
                return(serverObject.AsyncProcessMessage(reqMsg, replySink));
            }
            return(this._stackBuilderSink.AsyncProcessMessage(reqMsg, replySink));
        }
        public virtual IMessage SyncProcessMessage(IMessage reqMsg)
        {
            IMessage message = InternalSink.ValidateMessage(reqMsg);

            if (message != null)
            {
                return(message);
            }
            ArrayWithSize sideDynamicSinks = InternalSink.GetServerIdentity(reqMsg).ServerSideDynamicSinks;

            if (sideDynamicSinks != null)
            {
                DynamicPropertyHolder.NotifyDynamicSinks(reqMsg, sideDynamicSinks, false, true, false);
            }
            IMessageSink messageSink = this._stackBuilderSink.ServerObject as IMessageSink;
            IMessage     msg         = messageSink == null?this._stackBuilderSink.SyncProcessMessage(reqMsg) : messageSink.SyncProcessMessage(reqMsg);

            if (sideDynamicSinks != null)
            {
                DynamicPropertyHolder.NotifyDynamicSinks(msg, sideDynamicSinks, false, false, false);
            }
            return(msg);
        }
 internal virtual IMessageSink GetObjectChain(IMessage reqMsg, out MarshalByRefObject obj)
 {
     return(InternalSink.GetServerIdentity(reqMsg).GetServerObjectChain(out obj));
 }
        public virtual IMessage SyncProcessMessage(IMessage msg)
        {
            IMessage message = InternalSink.ValidateMessage(msg);

            if (message != null)
            {
                return(message);
            }
            IMethodCallMessage methodCallMessage   = msg as IMethodCallMessage;
            LogicalCallContext logicalCallContext1 = (LogicalCallContext)null;
            object             data = Thread.CurrentThread.GetMutableExecutionContext().LogicalCallContext.GetData("__xADCall");
            bool     flag           = false;
            IMessage msg1;

            try
            {
                object obj = this._server;
                StackBuilderSink.VerifyIsOkToCallMethod(obj, (IMethodMessage)methodCallMessage);
                LogicalCallContext logicalCallContext2 = methodCallMessage == null ? (LogicalCallContext)msg.Properties[(object)"__CallContext"] : methodCallMessage.LogicalCallContext;
                logicalCallContext1 = CallContext.SetLogicalCallContext(logicalCallContext2);
                flag = true;
                logicalCallContext2.PropagateIncomingHeadersToCallContext(msg);
                StackBuilderSink.PreserveThreadPrincipalIfNecessary(logicalCallContext2, logicalCallContext1);
                if (this.IsOKToStackBlt((IMethodMessage)methodCallMessage, obj) && ((Message)methodCallMessage).Dispatch(obj))
                {
                    msg1 = (IMessage) new StackBasedReturnMessage();
                    ((StackBasedReturnMessage)msg1).InitFields((Message)methodCallMessage);
                    LogicalCallContext logicalCallContext3 = Thread.CurrentThread.GetMutableExecutionContext().LogicalCallContext;
                    logicalCallContext3.PropagateOutgoingHeadersToMessage(msg1);
                    ((StackBasedReturnMessage)msg1).SetLogicalCallContext(logicalCallContext3);
                }
                else
                {
                    MethodBase methodBase = StackBuilderSink.GetMethodBase((IMethodMessage)methodCallMessage);
                    object[]   outArgs1   = (object[])null;
                    RemotingMethodCachedData reflectionCachedData = InternalRemotingServices.GetReflectionCachedData(methodBase);
                    object[] args = Message.CoerceArgs((IMethodMessage)methodCallMessage, reflectionCachedData.Parameters);
                    object   ret  = this.PrivateProcessMessage(methodBase.MethodHandle, args, obj, out outArgs1);
                    this.CopyNonByrefOutArgsFromOriginalArgs(reflectionCachedData, args, ref outArgs1);
                    LogicalCallContext logicalCallContext3 = Thread.CurrentThread.GetMutableExecutionContext().LogicalCallContext;
                    if (data != null && (bool)data && logicalCallContext3 != null)
                    {
                        logicalCallContext3.RemovePrincipalIfNotSerializable();
                    }
                    object[]           outArgs2     = outArgs1;
                    int                outArgsCount = outArgs2 == null ? 0 : outArgs1.Length;
                    LogicalCallContext callCtx      = logicalCallContext3;
                    IMethodCallMessage mcm          = methodCallMessage;
                    msg1 = (IMessage) new ReturnMessage(ret, outArgs2, outArgsCount, callCtx, mcm);
                    logicalCallContext3.PropagateOutgoingHeadersToMessage(msg1);
                    CallContext.SetLogicalCallContext(logicalCallContext1);
                }
            }
            catch (Exception ex)
            {
                IMethodCallMessage mcm = methodCallMessage;
                msg1 = (IMessage) new ReturnMessage(ex, mcm);
                ((ReturnMessage)msg1).SetLogicalCallContext(methodCallMessage.LogicalCallContext);
                if (flag)
                {
                    CallContext.SetLogicalCallContext(logicalCallContext1);
                }
            }
            return(msg1);
        }
Exemple #20
0
 public virtual IMessage SyncProcessMessage(IMessage reqMsg)
 {
     return(InternalSink.ValidateMessage(reqMsg) ?? Thread.CurrentContext.GetClientContextChain().SyncProcessMessage(reqMsg));
 }
        public virtual IMessage SyncProcessMessage(IMessage msg)
        {
            IMessage message = InternalSink.ValidateMessage(msg);

            if (message != null)
            {
                return(message);
            }
            IMethodCallMessage methodCallMessage   = msg as IMethodCallMessage;
            LogicalCallContext logicalCallContext  = null;
            LogicalCallContext logicalCallContext2 = Thread.CurrentThread.GetMutableExecutionContext().LogicalCallContext;
            object             data = logicalCallContext2.GetData("__xADCall");
            bool     flag           = false;
            IMessage message2;

            try
            {
                object server = this._server;
                StackBuilderSink.VerifyIsOkToCallMethod(server, methodCallMessage);
                LogicalCallContext logicalCallContext3;
                if (methodCallMessage != null)
                {
                    logicalCallContext3 = methodCallMessage.LogicalCallContext;
                }
                else
                {
                    logicalCallContext3 = (LogicalCallContext)msg.Properties["__CallContext"];
                }
                logicalCallContext = CallContext.SetLogicalCallContext(logicalCallContext3);
                flag = true;
                logicalCallContext3.PropagateIncomingHeadersToCallContext(msg);
                StackBuilderSink.PreserveThreadPrincipalIfNecessary(logicalCallContext3, logicalCallContext);
                if (this.IsOKToStackBlt(methodCallMessage, server) && ((Message)methodCallMessage).Dispatch(server))
                {
                    message2 = new StackBasedReturnMessage();
                    ((StackBasedReturnMessage)message2).InitFields((Message)methodCallMessage);
                    LogicalCallContext logicalCallContext4 = Thread.CurrentThread.GetMutableExecutionContext().LogicalCallContext;
                    logicalCallContext4.PropagateOutgoingHeadersToMessage(message2);
                    ((StackBasedReturnMessage)message2).SetLogicalCallContext(logicalCallContext4);
                }
                else
                {
                    MethodBase methodBase = StackBuilderSink.GetMethodBase(methodCallMessage);
                    object[]   array      = null;
                    RemotingMethodCachedData reflectionCachedData = InternalRemotingServices.GetReflectionCachedData(methodBase);
                    object[] args = Message.CoerceArgs(methodCallMessage, reflectionCachedData.Parameters);
                    object   ret  = this.PrivateProcessMessage(methodBase.MethodHandle, args, server, out array);
                    this.CopyNonByrefOutArgsFromOriginalArgs(reflectionCachedData, args, ref array);
                    LogicalCallContext logicalCallContext5 = Thread.CurrentThread.GetMutableExecutionContext().LogicalCallContext;
                    if (data != null && (bool)data && logicalCallContext5 != null)
                    {
                        logicalCallContext5.RemovePrincipalIfNotSerializable();
                    }
                    message2 = new ReturnMessage(ret, array, (array == null) ? 0 : array.Length, logicalCallContext5, methodCallMessage);
                    logicalCallContext5.PropagateOutgoingHeadersToMessage(message2);
                    CallContext.SetLogicalCallContext(logicalCallContext);
                }
            }
            catch (Exception e)
            {
                message2 = new ReturnMessage(e, methodCallMessage);
                ((ReturnMessage)message2).SetLogicalCallContext(methodCallMessage.LogicalCallContext);
                if (flag)
                {
                    CallContext.SetLogicalCallContext(logicalCallContext);
                }
            }
            return(message2);
        }
Exemple #22
0
        internal virtual IMessage SyncProcessMessage(IMessage msg, int methodPtr, bool fExecuteInContext)
        {
            // Validate message here
            IMessage errMsg = InternalSink.ValidateMessage(msg);

            if (errMsg != null)
            {
                return(errMsg);
            }

            IMethodCallMessage mcMsg = msg as IMethodCallMessage;

            IMessage           retMessage;
            LogicalCallContext oldCallCtx = null;

            try
            {
                Object server = _server;

                BCLDebug.Assert((server != null) == (!_bStatic),
                                "Invalid state in stackbuilder sink?");

                // validate the method base if necessary
                VerifyIsOkToCallMethod(server, mcMsg);

                // install call context onto the thread, holding onto
                // the one that is currently on the thread

                LogicalCallContext messageCallContext = null;
                if (mcMsg != null)
                {
                    messageCallContext = mcMsg.LogicalCallContext;
                }
                else
                {
                    messageCallContext = (LogicalCallContext)msg.Properties["__CallContext"];
                }

                oldCallCtx = CallContext.SetLogicalCallContext(messageCallContext);
                messageCallContext.PropagateIncomingHeadersToCallContext(msg);

                PreserveThreadPrincipalIfNecessary(messageCallContext, oldCallCtx);


                // NOTE: target for dispatch will be NULL when the StackBuilderSink
                // is used for async delegates on static methods.

                RemotingServices.LogRemotingStage(RemotingServices.SERVER_MSG_STACK_BUILD);

                // *** NOTE ***
                // Although we always pass _server to these calls in the EE,
                // when we execute using Message::Dispatch we are using TP as
                // the this-ptr ... (what the call site thinks is the this-ptr)
                // when we execute using StackBuilderSink::PrivatePM we use
                // _server as the this-ptr (which could be different if there
                // is interception for strictly MBR types in the same AD).
                // ************
                if (IsOKToStackBlt(mcMsg, server) &&
                    ((Message)mcMsg).Dispatch(server, fExecuteInContext))
                {
                    //retMessage = StackBasedReturnMessage.GetObjectFromPool((Message)mcMsg);
                    retMessage = new StackBasedReturnMessage();
                    ((StackBasedReturnMessage)retMessage).InitFields((Message)mcMsg);

                    // call context could be different then the one from before the call.
                    LogicalCallContext latestCallContext = CallContext.GetLogicalCallContext();
                    // retrieve outgoing response headers
                    latestCallContext.PropagateOutgoingHeadersToMessage(retMessage);

                    // Install call context back into Message (from the thread)
                    ((StackBasedReturnMessage)retMessage).SetLogicalCallContext(latestCallContext);
                }
                else
                {
                    MethodBase mb      = GetMethodBase(mcMsg);
                    Object[]   outArgs = null;
                    Object     ret     = null;

                    RemotingMethodCachedData methodCache =
                        InternalRemotingServices.GetReflectionCachedData(mb);

                    Message.DebugOut("StackBuilderSink::Calling PrivateProcessMessage\n");

                    Object[] args = Message.CoerceArgs(mcMsg, methodCache.Parameters);

                    ret = PrivateProcessMessage(
                        mb,
                        args,
                        server,
                        methodPtr,
                        fExecuteInContext,
                        out outArgs);
                    CopyNonByrefOutArgsFromOriginalArgs(methodCache, args, ref outArgs);


                    // call context could be different then the one from before the call.
                    LogicalCallContext latestCallContext = CallContext.GetLogicalCallContext();

                    retMessage = new ReturnMessage(
                        ret,
                        outArgs,
                        (outArgs == null ? 0 : outArgs.Length),
                        latestCallContext,
                        mcMsg);

                    // retrieve outgoing response headers
                    latestCallContext.PropagateOutgoingHeadersToMessage(retMessage);
                }

                // restore the call context on the thread
                CallContext.SetLogicalCallContext(oldCallCtx);
            } catch (Exception e)
            {
                Message.DebugOut(
                    "StackBuilderSink::The server object probably threw an exception " +
                    e.Message + e.StackTrace + "\n");
                retMessage = new ReturnMessage(e, mcMsg);
                ((ReturnMessage)retMessage).SetLogicalCallContext(mcMsg.LogicalCallContext);

                if (oldCallCtx != null)
                {
                    CallContext.SetLogicalCallContext(oldCallCtx);
                }
            }


            RemotingServices.LogRemotingStage(RemotingServices.SERVER_RET_SINK_CHAIN);
            return(retMessage);
        }
        internal virtual IMessage SyncProcessMessage(IMessage msg, int methodPtr, bool fExecuteInContext)
        {
            IMessage message3;
            IMessage message = InternalSink.ValidateMessage(msg);

            if (message != null)
            {
                return(message);
            }
            IMethodCallMessage message2          = msg as IMethodCallMessage;
            LogicalCallContext threadCallContext = null;
            object             obj2 = CallContext.GetLogicalCallContext().GetData("__xADCall");
            bool flag = false;

            try
            {
                object server = this._server;
                VerifyIsOkToCallMethod(server, message2);
                LogicalCallContext callCtx = null;
                if (message2 != null)
                {
                    callCtx = message2.LogicalCallContext;
                }
                else
                {
                    callCtx = (LogicalCallContext)msg.Properties["__CallContext"];
                }
                threadCallContext = CallContext.SetLogicalCallContext(callCtx);
                flag = true;
                callCtx.PropagateIncomingHeadersToCallContext(msg);
                PreserveThreadPrincipalIfNecessary(callCtx, threadCallContext);
                if (this.IsOKToStackBlt(message2, server) && ((Message)message2).Dispatch(server, fExecuteInContext))
                {
                    message3 = new StackBasedReturnMessage();
                    ((StackBasedReturnMessage)message3).InitFields((Message)message2);
                    LogicalCallContext context4 = CallContext.GetLogicalCallContext();
                    context4.PropagateOutgoingHeadersToMessage(message3);
                    ((StackBasedReturnMessage)message3).SetLogicalCallContext(context4);
                    return(message3);
                }
                MethodBase methodBase = GetMethodBase(message2);
                object[]   outArgs    = null;
                object     ret        = null;
                RemotingMethodCachedData reflectionCachedData = InternalRemotingServices.GetReflectionCachedData(methodBase);
                object[] args = Message.CoerceArgs(message2, reflectionCachedData.Parameters);
                ret = this.PrivateProcessMessage(methodBase.MethodHandle, args, server, methodPtr, fExecuteInContext, out outArgs);
                this.CopyNonByrefOutArgsFromOriginalArgs(reflectionCachedData, args, ref outArgs);
                LogicalCallContext logicalCallContext = CallContext.GetLogicalCallContext();
                if (((obj2 != null) && ((bool)obj2)) && (logicalCallContext != null))
                {
                    logicalCallContext.RemovePrincipalIfNotSerializable();
                }
                message3 = new ReturnMessage(ret, outArgs, (outArgs == null) ? 0 : outArgs.Length, logicalCallContext, message2);
                logicalCallContext.PropagateOutgoingHeadersToMessage(message3);
                CallContext.SetLogicalCallContext(threadCallContext);
            }
            catch (Exception exception)
            {
                message3 = new ReturnMessage(exception, message2);
                ((ReturnMessage)message3).SetLogicalCallContext(message2.LogicalCallContext);
                if (flag)
                {
                    CallContext.SetLogicalCallContext(threadCallContext);
                }
            }
            return(message3);
        }
 private IMessageSink GetChannelSink(IMessage reqMsg)
 {
     return(InternalSink.GetIdentity(reqMsg).ChannelSink);
 }
        private IMessageSink GetChannelSink(IMessage reqMsg)
        {
            Identity identity = InternalSink.GetIdentity(reqMsg);

            return(identity.ChannelSink);
        }