Пример #1
0
        internal void DispatchMessage(Message message)
        {
            object res = null;

            try
            {
                MessageCall call = MessageCall.CreateFromMessagePayload(message.Payload);

                object[] args     = call.Args;
                Type[]   argTypes = new Type[(args == null) ? 0 : args.Length];

                if (args != null)
                {
                    for (int i = args.Length - 1; i >= 0; i--)
                    {
                        object arg = args[i];

                        argTypes[i] = (arg == null) ? typeof(object) : arg.GetType();
                    }
                }

                MethodInfo mi = m_serverClassToRemote.GetMethod(call.Name, argTypes);

                if (mi == null)
                {
                    throw new Exception(string.Format("Could not find remote method '{0}'", call.Name));
                }

                res = mi.Invoke(m_server, call.Args);
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    //If an exception is thrown in the target method, it will be packaged up as the InnerException
                    ex = ex.InnerException;
                }

                res = new Messaging.RemotedException(ex);
            }

            try
            {
                message.Reply(res);
            }
            catch
            {
            }
        }
Пример #2
0
        internal object SendMessage(EndPoint ep, int timeout, MessageCall call)
        {
            object data = call.CreateMessagePayload();

            byte[] payload = m_eng.CreateBinaryFormatter().Serialize(data);

            byte[] res = SendMessageInner(ep, timeout, payload);

            if (res == null)
            {
                throw new RemotingException(string.Format("Remote call '{0}' failed", call.Name));
            }

            object o = m_eng.CreateBinaryFormatter().Deserialize(res);

            Messaging.RemotedException ex = o as Messaging.RemotedException;

            if (ex != null)
            {
                ex.Raise();
            }

            return(o);
        }
Пример #3
0
        internal void DispatchMessage(Message message)
        {
            object res = null;

            try
            {
                MessageCall call = MessageCall.CreateFromMessagePayload(message.Payload);

                object[] args = call.Args;
                Type[] argTypes = new Type[(args == null) ? 0 : args.Length];

                if (args != null)
                {
                    for (int i = args.Length - 1; i >= 0; i--)
                    {
                        object arg = args[i];

                        argTypes[i] = (arg == null) ? typeof(object) : arg.GetType();
                    }
                }

                MethodInfo mi = m_serverClassToRemote.GetMethod(call.Name, argTypes);

                if (mi == null) throw new Exception(string.Format("Could not find remote method '{0}'", call.Name));

                res = mi.Invoke(m_server, call.Args);
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    //If an exception is thrown in the target method, it will be packaged up as the InnerException
                    ex = ex.InnerException;
                }

                res = new Messaging.RemotedException(ex);
            }

            try
            {
                message.Reply(res);
            }
            catch
            {
            }
        }