Beispiel #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);
        }
        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
Beispiel #3
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
Beispiel #4
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);
        }
Beispiel #5
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);
        }
Beispiel #6
0
        public static IMessage SyncDispatchMessage(IMessage msg)
        {
            IMessage msgRet    = null;
            bool     fIsOneWay = false;

            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);

                    MethodBase method = ((IMethodMessage)msg).MethodBase;

                    // Check if the method is one way. Dispatch one way calls in
                    // an asynchronous manner
                    fIsOneWay = RemotingServices.IsOneWay(method);
                }

                IMessageSink nextSink = ChannelServices.GetCrossContextChannelSink();

                if (!fIsOneWay)
                {
                    msgRet = nextSink.SyncProcessMessage(msg);
                }
                else
                {
                    nextSink.AsyncProcessMessage(msg, null);
                }
            }
            catch (Exception e)
            {
                if (!fIsOneWay)
                {
                    try
                    {
                        IMethodCallMessage mcm =
                            (IMethodCallMessage)((msg != null)?msg:new ErrorMessage());
                        msgRet = (IMessage) new ReturnMessage(e, mcm);
                        if (msg != null)
                        {
                            ((ReturnMessage)msgRet).SetLogicalCallContext(
                                mcm.LogicalCallContext);
                        }
                    }
                    catch (Exception)
                    {
                        // Fatal exception .. ignore
                    }
                }
            }

            return(msgRet);
        }
Beispiel #7
0
        public static ServerProcessing DispatchMessage(
            IServerChannelSinkStack sinkStack,
            IMessage msg,
            out IMessage replyMsg)
        {
            ServerProcessing processing = ServerProcessing.Complete;

            replyMsg = null;

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

                BCLDebug.Trace("REMOTE", "Dispatching for URI " + InternalSink.GetURI(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();

                // Check if the object has been disconnected or if it is
                // a well known object then we have to create it lazily.
                ServerIdentity srvId = CheckDisconnectedOrCreateWellKnownObject(msg);

                // Make sure that this isn't an AppDomain object since we don't allow
                //   calls to the AppDomain from out of process (and x-process calls
                //   are always dispatched through this method)
                if (srvId.ServerType == typeof(System.AppDomain))
                {
                    throw new RemotingException(
                              Environment.GetResourceString(
                                  "Remoting_AppDomainsCantBeCalledRemotely"));
                }


                IMethodCallMessage mcm = msg as IMethodCallMessage;

                if (mcm == null)
                {
                    // It's a plain IMessage, so just check to make sure that the
                    //   target object implements IMessageSink and dispatch synchronously.

                    if (!typeof(IMessageSink).IsAssignableFrom(srvId.ServerType))
                    {
                        throw new RemotingException(
                                  Environment.GetResourceString(
                                      "Remoting_AppDomainsCantBeCalledRemotely"));
                    }

                    processing = ServerProcessing.Complete;
                    replyMsg   = ChannelServices.GetCrossContextChannelSink().SyncProcessMessage(msg);
                }
                else
                {
                    // It's an IMethodCallMessage.

                    // Check if the method is one way. Dispatch one way calls in
                    // an asynchronous manner
                    MethodInfo method = (MethodInfo)mcm.MethodBase;

                    // X-process / X-machine calls should be to non-static
                    // public methods only! Non-public or static methods can't
                    // be called remotely.
                    if (!IsMethodReallyPublic(method) &&
                        !RemotingServices.IsMethodAllowedRemotely(method))
                    {
                        throw new RemotingException(
                                  Environment.GetResourceString(
                                      "Remoting_NonPublicOrStaticCantBeCalledRemotely"));
                    }

                    RemotingMethodCachedData cache = (RemotingMethodCachedData)
                                                     InternalRemotingServices.GetReflectionCachedData(method);

                    /*
                     *  FUTURE:
                     *  Dispatching asynchronously was cut from v1. We should reactivate
                     *  the following code in v1.x or v2.
                     *
                     * // look for async method version
                     * MethodInfo begin;
                     * MethodInfo end;
                     * ServerChannelSinkStack serverSinkStack = sinkStack as ServerChannelSinkStack;
                     * if ((sinkStack != null) &&
                     *  cache.GetAsyncMethodVersion(out begin, out end))
                     * {
                     *  processing = ServerProcessing.Async;
                     *  IMessage asyncMsg =
                     *      new AsyncMethodCallMessageWrapper(
                     *          (IMethodCallMessage)msg,
                     *          begin,
                     *          new AsyncCallback(sinkStack.ServerCallback),
                     *          null);
                     *  serverSinkStack.AsyncMessage = asyncMsg;
                     *  serverSinkStack.AsyncEnd = end;
                     *  serverSinkStack.Message = (IMethodCallMessage)msg;
                     *  asyncMsg.Properties["__SinkStack"] = sinkStack;
                     *
                     *  // We don't dispatch yet. That happens when the server transport sink
                     *  //   eventually calls sinkStack.StoreAndDispatch(...).
                     * }
                     * else
                     */
                    if (RemotingServices.IsOneWay(method))
                    {
                        processing = ServerProcessing.OneWay;
                        ChannelServices.GetCrossContextChannelSink().AsyncProcessMessage(msg, null);
                    }
                    else
                    {
                        // regular processing
                        processing = ServerProcessing.Complete;
                        if (!srvId.ServerType.IsContextful)
                        {
                            Object[] args = new Object[] { msg, srvId.ServerContext };
                            replyMsg = (IMessage)CrossContextChannel.SyncProcessMessageCallback(args);
                        }
                        else
                        {
                            replyMsg = ChannelServices.GetCrossContextChannelSink().SyncProcessMessage(msg);
                        }
                    }
                } // end of case for IMethodCallMessage
            }
            catch (Exception e)
            {
                if (processing != ServerProcessing.OneWay)
                {
                    try
                    {
                        IMethodCallMessage mcm =
                            (IMethodCallMessage)((msg != null)?msg:new ErrorMessage());
                        replyMsg = (IMessage) new ReturnMessage(e, mcm);
                        if (msg != null)
                        {
                            ((ReturnMessage)replyMsg).SetLogicalCallContext(
                                (LogicalCallContext)
                                msg.Properties[Message.CallContextKey]);
                        }
                    }
                    catch (Exception)
                    {
                        // Fatal exception .. ignore
                    }
                }
            }

            return(processing);
        } // DispatchMessage
        public static IMessage SyncDispatchMessage(IMessage msg)
        {
            IMessage msgRet    = null;
            bool     fIsOneWay = false;

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



                // For ContextBoundObject's,
                // 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();

                // FUTURE: transitionCall needs to implement IMethodMessage ..
                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);

                    MethodBase method = ((IMethodMessage)msg).MethodBase;

                    // Check if the method is one way. Dispatch one way calls in
                    // an asynchronous manner
                    fIsOneWay = RemotingServices.IsOneWay(method);
                }

                // FUTURE: for MBR objects we could skip the x-ctx channel sink
                IMessageSink nextSink = ChannelServices.GetCrossContextChannelSink();

                if (!fIsOneWay)
                {
                    msgRet = nextSink.SyncProcessMessage(msg);
                }
                else
                {
                    nextSink.AsyncProcessMessage(msg, null);
                }
            }
            catch (Exception e)
            {
                if (!fIsOneWay)
                {
                    try
                    {
                        IMethodCallMessage mcm =
                            (IMethodCallMessage)((msg != null)?msg:new ErrorMessage());
                        msgRet = (IMessage) new ReturnMessage(e, mcm);
                        if (msg != null)
                        {
                            ((ReturnMessage)msgRet).SetLogicalCallContext(
                                mcm.LogicalCallContext);
                        }
                    }
                    catch (Exception)
                    {
                        // Fatal exception .. ignore
                    }
                }
            }

            return(msgRet);
        }
        public static ServerProcessing DispatchMessage(
            IServerChannelSinkStack sinkStack,
            IMessage msg,
            out IMessage replyMsg)
        {
            ServerProcessing processing = ServerProcessing.Complete;

            replyMsg = null;

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

                BCLDebug.Trace("REMOTE", "Dispatching for URI " + InternalSink.GetURI(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();

                // Check if the object has been disconnected or if it is
                // a well known object then we have to create it lazily.
                ServerIdentity srvId = CheckDisconnectedOrCreateWellKnownObject(msg);

                // Make sure that this isn't an AppDomain object since we don't allow
                //   calls to the AppDomain from out of process (and x-process calls
                //   are always dispatched through this method)
                if (srvId.ServerType == typeof(System.AppDomain))
                {
                    throw new RemotingException(
                              Environment.GetResourceString(
                                  "Remoting_AppDomainsCantBeCalledRemotely"));
                }


                IMethodCallMessage mcm = msg as IMethodCallMessage;

                if (mcm == null)
                {
                    // It's a plain IMessage, so just check to make sure that the
                    //   target object implements IMessageSink and dispatch synchronously.

                    if (!typeof(IMessageSink).IsAssignableFrom(srvId.ServerType))
                    {
                        throw new RemotingException(
                                  Environment.GetResourceString(
                                      "Remoting_AppDomainsCantBeCalledRemotely"));
                    }

                    processing = ServerProcessing.Complete;
                    replyMsg   = ChannelServices.GetCrossContextChannelSink().SyncProcessMessage(msg);
                }
                else
                {
                    // It's an IMethodCallMessage.

                    // Check if the method is one way. Dispatch one way calls in
                    // an asynchronous manner
                    MethodInfo method = (MethodInfo)mcm.MethodBase;

                    // X-process / X-machine calls should be to non-static
                    // public methods only! Non-public or static methods can't
                    // be called remotely.
                    if ((!method.IsPublic || method.IsStatic) &&
                        !RemotingServices.IsMethodAllowedRemotely(method))
                    {
                        throw new RemotingException(
                                  Environment.GetResourceString(
                                      "Remoting_NonPublicOrStaticCantBeCalledRemotely"));
                    }

                    RemotingMethodCachedData cache = (RemotingMethodCachedData)
                                                     InternalRemotingServices.GetReflectionCachedData(method);

                    if (RemotingServices.IsOneWay(method))
                    {
                        processing = ServerProcessing.OneWay;
                        ChannelServices.GetCrossContextChannelSink().AsyncProcessMessage(msg, null);
                    }
                    else
                    {
                        // regular processing
                        processing = ServerProcessing.Complete;
                        replyMsg   = ChannelServices.GetCrossContextChannelSink().SyncProcessMessage(msg);
                    }
                } // end of case for IMethodCallMessage
            }
            catch (Exception e)
            {
                if (processing != ServerProcessing.OneWay)
                {
                    try
                    {
                        IMethodCallMessage mcm =
                            (IMethodCallMessage)((msg != null)?msg:new ErrorMessage());
                        replyMsg = (IMessage) new ReturnMessage(e, mcm);
                        if (msg != null)
                        {
                            ((ReturnMessage)replyMsg).SetLogicalCallContext(
                                (LogicalCallContext)
                                msg.Properties[Message.CallContextKey]);
                        }
                    }
                    catch (Exception)
                    {
                        // Fatal exception .. ignore
                    }
                }
            }

            return(processing);
        } // DispatchMessage