CoerceArgs() static private method

static private CoerceArgs ( IMethodMessage m ) : Object[]
m IMethodMessage
return Object[]
Beispiel #1
0
        internal static object[] CoerceArgs(IMethodMessage m)
        {
            MethodBase methodBase = m.MethodBase;
            RemotingMethodCachedData reflectionCachedData = InternalRemotingServices.GetReflectionCachedData(methodBase);

            return(Message.CoerceArgs(m, reflectionCachedData.Parameters));
        }
Beispiel #2
0
 internal static object[] CoerceArgs(IMethodMessage m, ParameterInfo[] pi)
 {
     return(Message.CoerceArgs(m.MethodBase, m.Args, pi));
 }
Beispiel #3
0
        public virtual IMessageCtrl AsyncProcessMessage(
            IMessage msg, IMessageSink replySink)
        {
            IMethodCallMessage mcMsg = (IMethodCallMessage)msg;

            IMessageCtrl       retCtrl    = null;
            IMessage           retMessage = null;
            LogicalCallContext oldCallCtx = null;

            try
            {
                LogicalCallContext callCtx = (LogicalCallContext)
                                             mcMsg.Properties[Message.CallContextKey];

                Object server = _server;

                // 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

                oldCallCtx = CallContext.SetLogicalCallContext(callCtx);
                // retrieve incoming headers
                callCtx.PropagateIncomingHeadersToCallContext(msg);

                PreserveThreadPrincipalIfNecessary(callCtx, oldCallCtx);

                // see if this is a server message that was dispatched asynchronously
                ServerChannelSinkStack sinkStack =
                    msg.Properties["__SinkStack"] as ServerChannelSinkStack;
                if (sinkStack != null)
                {
                    sinkStack.ServerObject = server;
                }

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

                MethodBase mb      = GetMethodBase(mcMsg);
                Object[]   outArgs = null;
                Object     ret     = null;
                RemotingMethodCachedData methodCache =
                    InternalRemotingServices.GetReflectionCachedData(mb);
                Object[] args = Message.CoerceArgs(mcMsg, methodCache.Parameters);

                ret = PrivateProcessMessage(mb,
                                            args,
                                            server,
                                            0,
                                            false,
                                            out outArgs);
                CopyNonByrefOutArgsFromOriginalArgs(methodCache, args, ref outArgs);

                if (replySink != null)
                {
                    // 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);

                    replySink.SyncProcessMessage(retMessage);
                }
            }
            catch (Exception e)
            {
                try
                {
                    if (replySink != null)
                    {
                        retMessage = new ReturnMessage(e, mcMsg);
                        ((ReturnMessage)retMessage).SetLogicalCallContext(
                            (LogicalCallContext)
                            mcMsg.Properties[Message.CallContextKey]);

                        replySink.SyncProcessMessage(retMessage);
                    }
                }
                catch (Exception)
                {
                    // Fatal error..  can't do anything ..
                    // bail out silently.
                }
            }
            finally
            {
                // restore the call context on the thread
                if (oldCallCtx != null)
                {
                    CallContext.SetLogicalCallContext(oldCallCtx);
                }
            }

            return(retCtrl);
        } // AsyncProcessMessage
Beispiel #4
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);
        }
        public virtual IMessageCtrl AsyncProcessMessage(IMessage msg, IMessageSink replySink)
        {
            IMethodCallMessage message           = (IMethodCallMessage)msg;
            IMessageCtrl       ctrl              = null;
            IMessage           message2          = null;
            LogicalCallContext threadCallContext = null;
            bool flag = false;

            try
            {
                try
                {
                    try
                    {
                        LogicalCallContext callCtx = (LogicalCallContext)message.Properties[Message.CallContextKey];
                        object             server  = this._server;
                        VerifyIsOkToCallMethod(server, message);
                        threadCallContext = CallContext.SetLogicalCallContext(callCtx);
                        flag = true;
                        callCtx.PropagateIncomingHeadersToCallContext(msg);
                        PreserveThreadPrincipalIfNecessary(callCtx, threadCallContext);
                        ServerChannelSinkStack stack = msg.Properties["__SinkStack"] as ServerChannelSinkStack;
                        if (stack != null)
                        {
                            stack.ServerObject = server;
                        }
                        MethodBase methodBase = GetMethodBase(message);
                        object[]   outArgs    = null;
                        object     ret        = null;
                        RemotingMethodCachedData reflectionCachedData = InternalRemotingServices.GetReflectionCachedData(methodBase);
                        object[] args = Message.CoerceArgs(message, reflectionCachedData.Parameters);
                        ret = this.PrivateProcessMessage(methodBase.MethodHandle, args, server, 0, false, out outArgs);
                        this.CopyNonByrefOutArgsFromOriginalArgs(reflectionCachedData, args, ref outArgs);
                        if (replySink != null)
                        {
                            LogicalCallContext logicalCallContext = CallContext.GetLogicalCallContext();
                            if (logicalCallContext != null)
                            {
                                logicalCallContext.RemovePrincipalIfNotSerializable();
                            }
                            message2 = new ReturnMessage(ret, outArgs, (outArgs == null) ? 0 : outArgs.Length, logicalCallContext, message);
                            logicalCallContext.PropagateOutgoingHeadersToMessage(message2);
                        }
                        return(ctrl);
                    }
                    catch (Exception exception)
                    {
                        if (replySink != null)
                        {
                            message2 = new ReturnMessage(exception, message);
                            ((ReturnMessage)message2).SetLogicalCallContext((LogicalCallContext)message.Properties[Message.CallContextKey]);
                        }
                    }
                    return(ctrl);
                }
                finally
                {
                    if (replySink != null)
                    {
                        replySink.SyncProcessMessage(message2);
                    }
                }
            }
            finally
            {
                if (flag)
                {
                    CallContext.SetLogicalCallContext(threadCallContext);
                }
            }
            return(ctrl);
        }
Beispiel #6
0
        [System.Security.SecurityCritical]  // auto-generated
        public virtual IMessageCtrl AsyncProcessMessage(
            IMessage msg, IMessageSink replySink)
        {
            IMethodCallMessage mcMsg = (IMethodCallMessage)msg;

            IMessageCtrl       retCtrl    = null;
            IMessage           retMessage = null;
            LogicalCallContext oldCallCtx = null;
            bool isCallContextSet         = false;

            try{
                try
                {
                    LogicalCallContext callCtx = (LogicalCallContext)
                                                 mcMsg.Properties[Message.CallContextKey];

                    Object server = _server;

                    // 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

                    oldCallCtx       = CallContext.SetLogicalCallContext(callCtx);
                    isCallContextSet = true;
                    // retrieve incoming headers
                    callCtx.PropagateIncomingHeadersToCallContext(msg);

                    PreserveThreadPrincipalIfNecessary(callCtx, oldCallCtx);

                    // see if this is a server message that was dispatched asynchronously
                    ServerChannelSinkStack sinkStack =
                        msg.Properties["__SinkStack"] as ServerChannelSinkStack;
                    if (sinkStack != null)
                    {
                        sinkStack.ServerObject = server;
                    }

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

                    MethodBase mb      = GetMethodBase(mcMsg);
                    Object[]   outArgs = null;
                    Object     ret     = null;
                    RemotingMethodCachedData methodCache =
                        InternalRemotingServices.GetReflectionCachedData(mb);
                    Object[] args = Message.CoerceArgs(mcMsg, methodCache.Parameters);

                    ret = PrivateProcessMessage(mb.MethodHandle,
                                                args,
                                                server,
                                                0,
                                                false,
                                                out outArgs);
                    CopyNonByrefOutArgsFromOriginalArgs(methodCache, args, ref outArgs);

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

                        if (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);
                    }
                }
                catch (Exception e)
                {
                    if (replySink != null)
                    {
                        retMessage = new ReturnMessage(e, mcMsg);
                        ((ReturnMessage)retMessage).SetLogicalCallContext(
                            (LogicalCallContext)
                            mcMsg.Properties[Message.CallContextKey]);
                    }
                }
                finally
                {
                    if (replySink != null)
                    {
                        // Call the reply sink without catching the exceptions
                        // in it. In v2.0 any exceptions in the callback for example
                        // would probably bring down the process
                        replySink.SyncProcessMessage(retMessage);
                    }
                }
            }
            finally {
                // restore the call context on the thread
                if (isCallContextSet)
                {
                    CallContext.SetLogicalCallContext(oldCallCtx);
                }
            }

            return(retCtrl);
        } // AsyncProcessMessage
        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);
        }
        public virtual IMessageCtrl AsyncProcessMessage(IMessage msg, IMessageSink replySink)
        {
            IMethodCallMessage methodCallMessage  = (IMethodCallMessage)msg;
            IMessageCtrl       result             = null;
            IMessage           message            = null;
            LogicalCallContext logicalCallContext = null;
            bool flag = false;

            try
            {
                try
                {
                    LogicalCallContext logicalCallContext2 = (LogicalCallContext)methodCallMessage.Properties[Message.CallContextKey];
                    object             server = this._server;
                    StackBuilderSink.VerifyIsOkToCallMethod(server, methodCallMessage);
                    logicalCallContext = CallContext.SetLogicalCallContext(logicalCallContext2);
                    flag = true;
                    logicalCallContext2.PropagateIncomingHeadersToCallContext(msg);
                    StackBuilderSink.PreserveThreadPrincipalIfNecessary(logicalCallContext2, logicalCallContext);
                    ServerChannelSinkStack serverChannelSinkStack = msg.Properties["__SinkStack"] as ServerChannelSinkStack;
                    if (serverChannelSinkStack != null)
                    {
                        serverChannelSinkStack.ServerObject = server;
                    }
                    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);
                    if (replySink != null)
                    {
                        LogicalCallContext logicalCallContext3 = Thread.CurrentThread.GetMutableExecutionContext().LogicalCallContext;
                        if (logicalCallContext3 != null)
                        {
                            logicalCallContext3.RemovePrincipalIfNotSerializable();
                        }
                        message = new ReturnMessage(ret, array, (array == null) ? 0 : array.Length, logicalCallContext3, methodCallMessage);
                        logicalCallContext3.PropagateOutgoingHeadersToMessage(message);
                    }
                }
                catch (Exception e)
                {
                    if (replySink != null)
                    {
                        message = new ReturnMessage(e, methodCallMessage);
                        ((ReturnMessage)message).SetLogicalCallContext((LogicalCallContext)methodCallMessage.Properties[Message.CallContextKey]);
                    }
                }
                finally
                {
                    if (replySink != null)
                    {
                        replySink.SyncProcessMessage(message);
                    }
                }
            }
            finally
            {
                if (flag)
                {
                    CallContext.SetLogicalCallContext(logicalCallContext);
                }
            }
            return(result);
        }
Beispiel #10
0
        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);
        }
Beispiel #11
0
        public virtual IMessageCtrl AsyncProcessMessage(IMessage msg, IMessageSink replySink)
        {
            IMethodCallMessage mcm1        = (IMethodCallMessage)msg;
            IMessageCtrl       messageCtrl = (IMessageCtrl)null;
            IMessage           msg1        = (IMessage)null;
            LogicalCallContext callCtx1    = (LogicalCallContext)null;
            bool flag = false;

            try
            {
                try
                {
                    LogicalCallContext logicalCallContext1 = (LogicalCallContext)mcm1.Properties[(object)Message.CallContextKey];
                    object             server = this._server;
                    StackBuilderSink.VerifyIsOkToCallMethod(server, (IMethodMessage)mcm1);
                    callCtx1 = CallContext.SetLogicalCallContext(logicalCallContext1);
                    flag     = true;
                    IMessage msg2 = msg;
                    logicalCallContext1.PropagateIncomingHeadersToCallContext(msg2);
                    LogicalCallContext threadCallContext = callCtx1;
                    StackBuilderSink.PreserveThreadPrincipalIfNecessary(logicalCallContext1, threadCallContext);
                    ServerChannelSinkStack channelSinkStack = msg.Properties[(object)"__SinkStack"] as ServerChannelSinkStack;
                    if (channelSinkStack != null)
                    {
                        channelSinkStack.ServerObject = server;
                    }
                    MethodBase methodBase = StackBuilderSink.GetMethodBase((IMethodMessage)mcm1);
                    object[]   outArgs1   = (object[])null;
                    RemotingMethodCachedData reflectionCachedData = InternalRemotingServices.GetReflectionCachedData(methodBase);
                    object[] args = Message.CoerceArgs((IMethodMessage)mcm1, reflectionCachedData.Parameters);
                    object   obj  = this.PrivateProcessMessage(methodBase.MethodHandle, args, server, out outArgs1);
                    this.CopyNonByrefOutArgsFromOriginalArgs(reflectionCachedData, args, ref outArgs1);
                    if (replySink != null)
                    {
                        LogicalCallContext logicalCallContext2 = Thread.CurrentThread.GetMutableExecutionContext().LogicalCallContext;
                        if (logicalCallContext2 != null)
                        {
                            logicalCallContext2.RemovePrincipalIfNotSerializable();
                        }
                        object             ret          = obj;
                        object[]           outArgs2     = outArgs1;
                        int                outArgsCount = outArgs2 == null ? 0 : outArgs1.Length;
                        LogicalCallContext callCtx2     = logicalCallContext2;
                        IMethodCallMessage mcm2         = mcm1;
                        msg1 = (IMessage) new ReturnMessage(ret, outArgs2, outArgsCount, callCtx2, mcm2);
                        logicalCallContext2.PropagateOutgoingHeadersToMessage(msg1);
                    }
                }
                catch (Exception ex)
                {
                    if (replySink != null)
                    {
                        msg1 = (IMessage) new ReturnMessage(ex, mcm1);
                        ((ReturnMessage)msg1).SetLogicalCallContext((LogicalCallContext)mcm1.Properties[(object)Message.CallContextKey]);
                    }
                }
                finally
                {
                    if (replySink != null)
                    {
                        replySink.SyncProcessMessage(msg1);
                    }
                }
            }
            finally
            {
                if (flag)
                {
                    CallContext.SetLogicalCallContext(callCtx1);
                }
            }
            return(messageCtrl);
        }