Inheritance: IMethodReturnMessage, IInternalMessage
        private LogicalCallContext FetchLogicalCallContext()
        {
            ReturnMessage returnMessage = this._mrmsg as ReturnMessage;

            if (returnMessage != null)
            {
                return(returnMessage.GetLogicalCallContext());
            }
            MethodResponse methodResponse = this._mrmsg as MethodResponse;

            if (methodResponse != null)
            {
                return(methodResponse.GetLogicalCallContext());
            }
            StackBasedReturnMessage stackBasedReturnMessage = this._mrmsg as StackBasedReturnMessage;

            if (stackBasedReturnMessage != null)
            {
                return(stackBasedReturnMessage.GetLogicalCallContext());
            }
            throw new RemotingException(Environment.GetResourceString("Remoting_Message_BadType"));
        }
Ejemplo n.º 2
0
        [System.Security.SecurityCritical]  // auto-generated
        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; 

            LogicalCallContext lcc = CallContext.GetLogicalCallContext();
            object xADCall = lcc.GetData(CrossAppDomainSink.LCC_DATA_KEY);
 
            bool isCallContextSet = false;
            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);
                isCallContextSet = true;
 
                messageCallContext.PropagateIncomingHeadersToCallContext(msg);
 
                PreserveThreadPrincipalIfNecessary(messageCallContext, oldCallCtx); 

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

                // *** 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.MethodHandle,
                                        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(); 
 
                    if (xADCall != null && ((bool)xADCall) == true && latestCallContext != null)
                    { 
                        // Special case Principal since if might not be serializable before returning
                        // ReturnMessage
                        latestCallContext.RemovePrincipalIfNotSerializable();
                    } 

                    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 (isCallContextSet)
                    CallContext.SetLogicalCallContext(oldCallCtx);
            }
 

            return retMessage; 
        } 
Ejemplo n.º 3
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);
        }
        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);
        }