DebugOut() private method

private DebugOut ( String s ) : void
s String
return void
Beispiel #1
0
        public virtual IMessageCtrl AsyncProcessMessage(IMessage reqMsg, IMessageSink replySink)
        {
            Message.DebugOut("---------------------------Envoy Chain Terminator: AsyncProcessMessage");
            IMessageCtrl msgCtrl = null;
            IMessage     errMsg  = ValidateMessage(reqMsg);

            if (errMsg != null)
            {
                // Notify replySink of error if we can
                if (replySink != null)
                {
                    replySink.SyncProcessMessage(errMsg);
                }
            }
            else
            {
                msgCtrl = Thread.CurrentContext.GetClientContextChain().AsyncProcessMessage(reqMsg, replySink);
            }
            return(msgCtrl);
        }
        [System.Security.SecurityCritical]  // auto-generated
        internal static ServerIdentity GetServerIdentity(IMessage reqMsg)
        {
            ServerIdentity srvID   = null;
            bool           bOurMsg = false;
            String         objURI  = null;

            IInternalMessage iim = reqMsg as IInternalMessage;

            if (iim != null)
            {
                Message.DebugOut("GetServerIdentity.ServerIdentity from IInternalMessage\n");
                srvID   = ((IInternalMessage)reqMsg).ServerIdentityObject;
                bOurMsg = true;
            }
            else if (reqMsg is InternalMessageWrapper)
            {
                srvID = (ServerIdentity)((InternalMessageWrapper)reqMsg).GetServerIdentityObject();
            }

            // Try the slow path if the identity has not been obtained yet
            if (null == srvID)
            {
                Message.DebugOut("GetServerIdentity.ServerIdentity from IMethodCallMessage\n");
                objURI = GetURI(reqMsg);
                Identity id =
                    IdentityHolder.ResolveIdentity(objURI);
                if (id is ServerIdentity)
                {
                    srvID = (ServerIdentity)id;

                    // Cache the serverIdentity in the message
                    if (bOurMsg)
                    {
                        iim.ServerIdentityObject = srvID;
                    }
                }
            }

            return(srvID);
        }
        public virtual IMessageCtrl AsyncProcessMessage(IMessage reqMsg, IMessageSink replySink)
        {
            Message.DebugOut("---------------------------Envoy Chain Terminator: AsyncProcessMessage");
            IMessageCtrl msgCtrl = null;
            IMessage     errMsg  = ValidateMessage(reqMsg);

            if (errMsg != null)
            {
                // Notify replySink of error if we can
                // FUTURE: is it okay to reply right away before we return
                // the IMessageCtrl for the original call?
                if (replySink != null)
                {
                    replySink.SyncProcessMessage(errMsg);
                }
            }
            else
            {
                msgCtrl = Thread.CurrentContext.GetClientContextChain().AsyncProcessMessage(reqMsg, replySink);
            }
            return(msgCtrl);
        }
        [System.Security.SecurityCritical]  // auto-generated_required
        public virtual ISerializationSurrogate GetSurrogate(Type type, StreamingContext context, out ISurrogateSelector ssout)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            Contract.EndContractBlock();

            Message.DebugOut("Entered  GetSurrogate for " + type.FullName + "\n");

            if (type.IsMarshalByRef)
            {
                Message.DebugOut("Selected surrogate for " + type.FullName);
                ssout = this;
                return(_remotingSurrogate);
            }
            else if (s_IMethodCallMessageType.IsAssignableFrom(type) ||
                     s_IMethodReturnMessageType.IsAssignableFrom(type))
            {
                ssout = this;
                return(_messageSurrogate);
            }
            else if (s_ObjRefType.IsAssignableFrom(type))
            {
                ssout = this;
                return(_objRefSurrogate);
            }
            else if (_next != null)
            {
                return(_next.GetSurrogate(type, context, out ssout));
            }
            else
            {
                ssout = null;
                return(null);
            }
        } // GetSurrogate
Beispiel #5
0
        public virtual void GetObjectData(Object obj, SerializationInfo info, StreamingContext context)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }

            if (info == null)
            {
                throw new ArgumentNullException("info");
            }

            bool           returnMessage       = false;
            bool           constructionMessage = false;
            IMethodMessage msg = obj as IMethodMessage;

            if (null != msg)
            {
                IDictionaryEnumerator de = msg.Properties.GetEnumerator();
                if (msg is IMethodCallMessage)
                {
                    if (obj is IConstructionCallMessage)
                    {
                        constructionMessage = true;
                    }
                    info.SetType(constructionMessage ? _constructionCallType : _methodCallType);
                }
                else
                {
                    IMethodReturnMessage mrm = msg as IMethodReturnMessage;
                    if (null != mrm)
                    {
                        returnMessage = true;
                        info.SetType((obj is IConstructionReturnMessage) ? _constructionResponseType : _methodResponseType);
                        if (((IMethodReturnMessage)msg).Exception != null)
                        {
                            info.AddValue("__fault", ((IMethodReturnMessage)msg).Exception, _exceptionType);
                        }
                    }
                    else
                    {
                        throw new RemotingException(Environment.GetResourceString("Remoting_InvalidMsg"));
                    }
                }

                while (de.MoveNext())
                {
                    if ((obj == _ss.GetRootObject()) && (_ss.Filter != null) && _ss.Filter((String)de.Key, de.Value))
                    {
                        continue;
                    }

                    if (de.Value != null)
                    {
                        String key = de.Key.ToString();
                        if (key.Equals("__CallContext"))
                        {
                            // If the CallContext has only the call Id, then there is no need to put the entire
                            // LogicalCallContext type on the wire
                            LogicalCallContext lcc = (LogicalCallContext)de.Value;
                            if (lcc.HasInfo)
                            {
                                info.AddValue(key, lcc);
                            }
                            else
                            {
                                info.AddValue(key, lcc.RemotingData.LogicalCallID);
                            }
                        }
                        else if (key.Equals("__MethodSignature"))
                        {
                            // If the method is not overloaded, the method signature does not need to go on the wire
                            // note - IsMethodOverloaded does not work well with constructors
                            if (constructionMessage || RemotingServices.IsMethodOverloaded(msg))
                            {
                                info.AddValue(key, de.Value);
                                continue;
                            }
                            Message.DebugOut("MessageSurrogate::GetObjectData. Method not overloaded, so no MethodSignature \n");
                        }
                        else
                        {
                            returnMessage = returnMessage;
                            info.AddValue(key, de.Value);
                        }
                    }
                    else
                    {
                        info.AddValue(de.Key.ToString(), de.Value, _objectType);
                    }
                }
            }
            else
            {
                throw new RemotingException(Environment.GetResourceString("Remoting_InvalidMsg"));
            }
        }
Beispiel #6
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);
        }
        [System.Security.SecurityCritical]  // auto-generated
        public virtual IMessageCtrl AsyncProcessMessage(IMessage reqMsg, IMessageSink replySink)
        {
            Message.DebugOut("+++++++++++++++++++++++++ CliCtxTerminator: AsyncProcessMsg");
            IMessage     errMsg  = ValidateMessage(reqMsg);
            IMessageCtrl msgCtrl = null;

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

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

                    RemotingServices.CORProfilerRemotingClientSendingMessage(out g, true);

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

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

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

                Context cliCtx = Thread.CurrentContext;

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

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

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

                IMessageSink channelSink = GetChannelSink(reqMsg);

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

                // Move to default context unless we are going through
                // the cross-context channel
                if (channelSink != CrossContextChannel.MessageSink)
                {
                    msgCtrl = (IMessageCtrl)Thread.CurrentThread.InternalCrossContextCallback(Context.DefaultContext, xctxDel, args);
                }
                else
                {
                    msgCtrl = (IMessageCtrl)xctxDel(args);
                }
            }
            return(msgCtrl);
        }
        [System.Security.SecurityCritical]  // auto-generated
        public virtual IMessage     SyncProcessMessage(IMessage reqMsg)
        {
            Message.DebugOut("+++++++++++++++++++++++++ CliCtxTerminator: SyncProcessMsg");
            IMessage errMsg = ValidateMessage(reqMsg);

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

            Context ctx = Thread.CurrentContext;

            bool bHasDynamicSinks =
                ctx.NotifyDynamicSinks(reqMsg,
                                       true,  // bCliSide
                                       true,  // bStart
                                       false, // bAsync
                                       true); // bNotifyGlobals

            IMessage replyMsg;

            if (reqMsg is IConstructionCallMessage)
            {
                errMsg = ctx.NotifyActivatorProperties(
                    reqMsg,
                    false /*bServerSide*/);
                if (errMsg != null)
                {
                    return(errMsg);
                }

                replyMsg = ((IConstructionCallMessage)reqMsg).Activator.Activate(
                    (IConstructionCallMessage)reqMsg);
                BCLDebug.Assert(replyMsg is IConstructionReturnMessage, "bad ctorRetMsg");
                errMsg = ctx.NotifyActivatorProperties(
                    replyMsg,
                    false /*bServerSide*/);
                if (errMsg != null)
                {
                    return(errMsg);
                }
            }
            else
            {
                replyMsg = null;
                ChannelServices.NotifyProfiler(reqMsg, RemotingProfilerEvent.ClientSend);

                Object[] args = new Object[] { null, null };

                IMessageSink channelSink = GetChannelSink(reqMsg);

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

                InternalCrossContextDelegate xctxDel = new InternalCrossContextDelegate(SyncProcessMessageCallback);

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

                ChannelServices.NotifyProfiler(replyMsg, RemotingProfilerEvent.ClientReceive);
            }


            if (bHasDynamicSinks)
            {
                ctx.NotifyDynamicSinks(reqMsg,
                                       true,  // bCliSide
                                       false, // bStart
                                       false, // bAsync
                                       true); // bNotifyGlobals
            }

            return(replyMsg);
        }
        public virtual IMessage     SyncProcessMessage(IMessage reqMsg)
        {
            Message.DebugOut("+++++++++++++++++++++++++ CliCtxTerminator: SyncProcessMsg");
            IMessage errMsg = ValidateMessage(reqMsg);

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

            Context ctx = Thread.CurrentContext;

            bool bHasDynamicSinks =
                ctx.NotifyDynamicSinks(reqMsg,
                                       true,  // bCliSide
                                       true,  // bStart
                                       false, // bAsync
                                       true); // bNotifyGlobals

            IMessage replyMsg;

            if (reqMsg is IConstructionCallMessage)
            {
                errMsg = ctx.NotifyActivatorProperties(
                    reqMsg,
                    false /*bServerSide*/);
                if (errMsg != null)
                {
                    return(errMsg);
                }

                replyMsg = ((IConstructionCallMessage)reqMsg).Activator.Activate(
                    (IConstructionCallMessage)reqMsg);
                BCLDebug.Assert(replyMsg is IConstructionReturnMessage, "bad ctorRetMsg");
                errMsg = ctx.NotifyActivatorProperties(
                    replyMsg,
                    false /*bServerSide*/);
                if (errMsg != null)
                {
                    return(errMsg);
                }
            }
            else
            {
                ChannelServices.NotifyProfiler(reqMsg, RemotingProfilerEvent.ClientSend);

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

                if (channelSink != CrossContextChannel.MessageSink)
                {
                    Thread.CurrentThread.ReturnToContext(ref frame);
                }

                ChannelServices.NotifyProfiler(replyMsg, RemotingProfilerEvent.ClientReceive);
            }


            if (bHasDynamicSinks)
            {
                ctx.NotifyDynamicSinks(reqMsg,
                                       true,  // bCliSide
                                       false, // bStart
                                       false, // bAsync
                                       true); // bNotifyGlobals
            }

            return(replyMsg);
        }
        [System.Security.SecurityCritical]  // auto-generated_required
        public virtual void GetObjectData(Object obj, SerializationInfo info, StreamingContext context)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }

            if (info == null)
            {
                throw new ArgumentNullException("info");
            }
            Contract.EndContractBlock();

            bool           returnMessage       = false;
            bool           constructionMessage = false;
            IMethodMessage msg = obj as IMethodMessage;

            if (null != msg)
            {
                IDictionaryEnumerator de = msg.Properties.GetEnumerator();
                if (msg is IMethodCallMessage)
                {
                    if (obj is IConstructionCallMessage)
                    {
                        constructionMessage = true;
                    }
                    info.SetType(constructionMessage ? _constructionCallType : _methodCallType);
                }
                else
                {
                    IMethodReturnMessage mrm = msg as IMethodReturnMessage;
                    if (null != mrm)
                    {
                        returnMessage = true;
                        info.SetType((obj is IConstructionReturnMessage) ? _constructionResponseType : _methodResponseType);
                        if (((IMethodReturnMessage)msg).Exception != null)
                        {
                            info.AddValue("__fault", ((IMethodReturnMessage)msg).Exception, _exceptionType);
                        }
                    }
                    else
                    {
                        throw new RemotingException(Environment.GetResourceString("Remoting_InvalidMsg"));
                    }
                }

                while (de.MoveNext())
                {
                    if ((obj == _ss.GetRootObject()) && (_ss.Filter != null) && _ss.Filter((String)de.Key, de.Value))
                    {
                        continue;
                    }

                    if (de.Value != null)
                    {
                        String key = de.Key.ToString();
                        if (key.Equals("__CallContext"))
                        {
                            // If the CallContext has only the call Id, then there is no need to put the entire
                            // LogicalCallContext type on the wire
                            LogicalCallContext lcc = (LogicalCallContext)de.Value;
                            if (lcc.HasInfo)
                            {
                                info.AddValue(key, lcc);
                            }
                            else
                            {
                                info.AddValue(key, lcc.RemotingData.LogicalCallID);
                            }
                        }
                        else if (key.Equals("__MethodSignature"))
                        {
                            // If the method is not overloaded, the method signature does not need to go on the wire
                            // note - IsMethodOverloaded does not work well with constructors
                            if (constructionMessage || RemotingServices.IsMethodOverloaded(msg))
                            {
                                info.AddValue(key, de.Value);
                                continue;
                            }
                            Message.DebugOut("MessageSurrogate::GetObjectData. Method not overloaded, so no MethodSignature \n");
                        }
                        else
                        {
#if false
                            /* If the streaming context says this is a x-domain call, then there is no
                             *  need to include the following fields in the return message. Right now I am not sure
                             *  how to identify a cross-domain streaming context - Ashok
                             */
                            if (returnMessage &&
                                (key.Equals("__Uri") ||
                                 key.Equals("__MethodName") ||
                                 key.Equals("__TypeName")))
                            {
                                continue;
                            }
                            else
#endif
#pragma warning disable 1717  // assignment to self
                            returnMessage = returnMessage;
#pragma warning restore 1717
                            info.AddValue(key, de.Value);
                        }
                    }
                    else
                    {
                        info.AddValue(de.Key.ToString(), de.Value, _objectType);
                    }
                }
            }
            else
            {
                throw new RemotingException(Environment.GetResourceString("Remoting_InvalidMsg"));
            }
        }