Ejemplo n.º 1
0
        public static IMessageCtrl AsyncDispatchMessage(IMessage msg, IMessageSink replySink)
        {
            IMessageCtrl ctrl = null;

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

                // we must switch to the target context of the object and call the context chains etc...
                // Currenly XContextChannel does exactly so. So this method is just a wrapper..

                // Make sure that incoming calls are counted as a remote call. This way it
                // makes more sense on a server.
                IncrementRemoteCalls();

                if (!(msg is TransitionCall))
                {
                    // Check if the object has been disconnected or if it is
                    // a well known object then we have to create it lazily.
                    CheckDisconnectedOrCreateWellKnownObject(msg);
                }

                // FUTURE: This dispatches MarshalByRef objects in the default context
                // Ideally, MarshalByRef objects should be dispatched in any context.
                ctrl = ChannelServices.GetCrossContextChannelSink().AsyncProcessMessage(msg, replySink);
            }
            catch (Exception e)
            {
                if (null != replySink)
                {
                    try
                    {
                        IMethodCallMessage mcm    = (IMethodCallMessage)msg;
                        ReturnMessage      retMsg = new ReturnMessage(e, (IMethodCallMessage)msg);
                        if (msg != null)
                        {
                            retMsg.SetLogicalCallContext(mcm.LogicalCallContext);
                        }
                        replySink.SyncProcessMessage(retMsg);
                    }
                    catch (Exception)
                    {
                        // Fatal exception... ignore
                    }
                }
            }

            return(ctrl);
        } // AsyncDispatchMessage
Ejemplo n.º 2
0
        public static IMessageCtrl AsyncDispatchMessage(IMessage msg, IMessageSink replySink)
        {
            IMessageCtrl ctrl = null;

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


                IncrementRemoteCalls();

                if (!(msg is TransitionCall))
                {
                    // Check if the object has been disconnected or if it is
                    // a well known object then we have to create it lazily.
                    CheckDisconnectedOrCreateWellKnownObject(msg);
                }

                ctrl = ChannelServices.GetCrossContextChannelSink().AsyncProcessMessage(msg, replySink);
            }
            catch (Exception e)
            {
                if (null != replySink)
                {
                    try
                    {
                        IMethodCallMessage mcm    = (IMethodCallMessage)msg;
                        ReturnMessage      retMsg = new ReturnMessage(e, (IMethodCallMessage)msg);
                        if (msg != null)
                        {
                            retMsg.SetLogicalCallContext(mcm.LogicalCallContext);
                        }
                        replySink.SyncProcessMessage(retMsg);
                    }
                    catch (Exception)
                    {
                        // Fatal exception... ignore
                    }
                }
            }

            return(ctrl);
        } // AsyncDispatchMessage
        public static IMessageCtrl AsyncDispatchMessage(IMessage msg, IMessageSink replySink)
        {
            IMessageCtrl ctrl = null;

            try
            {
                if (msg == null)
                {
                    throw new ArgumentNullException("msg");
                }
                IncrementRemoteCalls();
                if (!(msg is TransitionCall))
                {
                    CheckDisconnectedOrCreateWellKnownObject(msg);
                }
                ctrl = GetCrossContextChannelSink().AsyncProcessMessage(msg, replySink);
            }
            catch (Exception exception)
            {
                if (replySink == null)
                {
                    return(ctrl);
                }
                try
                {
                    IMethodCallMessage message  = (IMethodCallMessage)msg;
                    ReturnMessage      message2 = new ReturnMessage(exception, (IMethodCallMessage)msg);
                    if (msg != null)
                    {
                        message2.SetLogicalCallContext(message.LogicalCallContext);
                    }
                    replySink.SyncProcessMessage(message2);
                }
                catch (Exception)
                {
                }
            }
            return(ctrl);
        }
Ejemplo n.º 4
0
        [System.Security.SecurityCritical]  // auto-generated
        public IMessage SyncProcessMessage(IMessage msg)
        {
            Contract.Assert( 
                Thread.CurrentContext.InternalContextID == _targetCtxID,
                "Transition message routed to wrong context"); 
 
            try
            { 
                LogicalCallContext oldcctx = Message.PropagateCallContextFromMessageToThread(msg);
                if (_delegate != null)
                {
                    _delegate(); 
                }
                else 
                { 
                    // This is the cross appdomain case, so we need to construct
                    //   the delegate and call on it. 
                    CallBackHelper cb = new CallBackHelper(
                                            _eeData,
                                            true /*fromEE*/,
                                            _targetDomainID); 
                    CrossContextDelegate ctxDel = new CrossContextDelegate(cb.Func);
                    ctxDel(); 
                } 
                Message.PropagateCallContextFromThreadToMessage(msg, oldcctx);
            } 

            catch (Exception e)
            {
                ReturnMessage retMsg = new ReturnMessage(e, new ErrorMessage()); 
                retMsg.SetLogicalCallContext(
                    (LogicalCallContext) msg.Properties[Message.CallContextKey]); 
                return retMsg; 
            }
 
            return this;
        }