Ejemplo n.º 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 = _serverClassToRemote.GetMethod(call.Name, argTypes);

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

                res = mi.Invoke(_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 RemotedException(ex);
            }

            try
            {
                message.Reply(res);
            }
            catch
            {
            }
        }
Ejemplo n.º 2
0
        internal object SendMessage(EndPoint ep, int timeout, MessageCall call)
        {
            object data = call.CreateMessagePayload();

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

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

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

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

            RemotedException ex = o as RemotedException;

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

            return(o);
        }