Ejemplo n.º 1
0
        public static IMessage SyncDispatchMessage(IMessage msg)
        {
            IMessage message = null;
            bool     flag    = false;

            try
            {
                if (msg == null)
                {
                    throw new ArgumentNullException("msg");
                }
                ChannelServices.IncrementRemoteCalls();
                if (!(msg is TransitionCall))
                {
                    ChannelServices.CheckDisconnectedOrCreateWellKnownObject(msg);
                    MethodBase methodBase = ((IMethodMessage)msg).MethodBase;
                    flag = RemotingServices.IsOneWay(methodBase);
                }
                IMessageSink crossContextChannelSink = ChannelServices.GetCrossContextChannelSink();
                if (!flag)
                {
                    message = crossContextChannelSink.SyncProcessMessage(msg);
                }
                else
                {
                    crossContextChannelSink.AsyncProcessMessage(msg, null);
                }
            }
            catch (Exception e)
            {
                if (!flag)
                {
                    try
                    {
                        IMessage message3;
                        if (msg == null)
                        {
                            IMessage message2 = new ErrorMessage();
                            message3 = message2;
                        }
                        else
                        {
                            message3 = msg;
                        }
                        IMethodCallMessage methodCallMessage = (IMethodCallMessage)message3;
                        message = new ReturnMessage(e, methodCallMessage);
                        if (msg != null)
                        {
                            ((ReturnMessage)message).SetLogicalCallContext(methodCallMessage.LogicalCallContext);
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            return(message);
        }
Ejemplo n.º 2
0
        public static IMessageCtrl AsyncDispatchMessage(IMessage msg, IMessageSink replySink)
        {
            IMessageCtrl messageCtrl = (IMessageCtrl)null;

            try
            {
                if (msg == null)
                {
                    throw new ArgumentNullException("msg");
                }
                ChannelServices.IncrementRemoteCalls();
                if (!(msg is TransitionCall))
                {
                    ChannelServices.CheckDisconnectedOrCreateWellKnownObject(msg);
                }
                messageCtrl = ChannelServices.GetCrossContextChannelSink().AsyncProcessMessage(msg, replySink);
            }
            catch (Exception ex1)
            {
                if (replySink != null)
                {
                    try
                    {
                        IMethodCallMessage methodCallMessage = (IMethodCallMessage)msg;
                        ReturnMessage      returnMessage     = new ReturnMessage(ex1, (IMethodCallMessage)msg);
                        if (msg != null)
                        {
                            returnMessage.SetLogicalCallContext(methodCallMessage.LogicalCallContext);
                        }
                        replySink.SyncProcessMessage((IMessage)returnMessage);
                    }
                    catch (Exception ex2)
                    {
                    }
                }
            }
            return(messageCtrl);
        }
Ejemplo n.º 3
0
        public static ServerProcessing DispatchMessage(IServerChannelSinkStack sinkStack, IMessage msg, out IMessage replyMsg)
        {
            ServerProcessing serverProcessing = ServerProcessing.Complete;

            replyMsg = (IMessage)null;
            try
            {
                if (msg == null)
                {
                    throw new ArgumentNullException("msg");
                }
                ChannelServices.IncrementRemoteCalls();
                ServerIdentity wellKnownObject = ChannelServices.CheckDisconnectedOrCreateWellKnownObject(msg);
                if (wellKnownObject.ServerType == typeof(AppDomain))
                {
                    throw new RemotingException(Environment.GetResourceString("Remoting_AppDomainsCantBeCalledRemotely"));
                }
                IMethodCallMessage methodCallMessage = msg as IMethodCallMessage;
                if (methodCallMessage == null)
                {
                    if (!typeof(IMessageSink).IsAssignableFrom(wellKnownObject.ServerType))
                    {
                        throw new RemotingException(Environment.GetResourceString("Remoting_AppDomainsCantBeCalledRemotely"));
                    }
                    serverProcessing = ServerProcessing.Complete;
                    replyMsg         = ChannelServices.GetCrossContextChannelSink().SyncProcessMessage(msg);
                }
                else
                {
                    MethodInfo mi = (MethodInfo)methodCallMessage.MethodBase;
                    if (!ChannelServices.IsMethodReallyPublic(mi) && !RemotingServices.IsMethodAllowedRemotely((MethodBase)mi))
                    {
                        throw new RemotingException(Environment.GetResourceString("Remoting_NonPublicOrStaticCantBeCalledRemotely"));
                    }
                    InternalRemotingServices.GetReflectionCachedData((MethodBase)mi);
                    if (RemotingServices.IsOneWay((MethodBase)mi))
                    {
                        serverProcessing = ServerProcessing.OneWay;
                        ChannelServices.GetCrossContextChannelSink().AsyncProcessMessage(msg, (IMessageSink)null);
                    }
                    else
                    {
                        serverProcessing = ServerProcessing.Complete;
                        if (!wellKnownObject.ServerType.IsContextful)
                        {
                            object[] args = new object[2] {
                                (object)msg, (object)wellKnownObject.ServerContext
                            };
                            replyMsg = (IMessage)CrossContextChannel.SyncProcessMessageCallback(args);
                        }
                        else
                        {
                            replyMsg = ChannelServices.GetCrossContextChannelSink().SyncProcessMessage(msg);
                        }
                    }
                }
            }
            catch (Exception ex1)
            {
                if (serverProcessing != ServerProcessing.OneWay)
                {
                    try
                    {
                        IMethodCallMessage mcm = msg != null ? (IMethodCallMessage)msg : (IMethodCallMessage) new ErrorMessage();
                        replyMsg = (IMessage) new ReturnMessage(ex1, mcm);
                        if (msg != null)
                        {
                            ((ReturnMessage)replyMsg).SetLogicalCallContext((LogicalCallContext)msg.Properties[(object)Message.CallContextKey]);
                        }
                    }
                    catch (Exception ex2)
                    {
                    }
                }
            }
            return(serverProcessing);
        }
Ejemplo n.º 4
0
 internal static void IncrementRemoteCalls()
 {
     ChannelServices.IncrementRemoteCalls(1L);
 }