public object Invoke(string methodName, params object[] args) { object cmd = new object[] { methodName, args }; object res = m_ep.SendMessage(m_selector, m_id, 1000, cmd); if (res != null) { Microsoft.SPOT.Messaging.Message.RemotedException ex = res as Microsoft.SPOT.Messaging.Message.RemotedException; if (ex != null) { ex.Raise(); } } return(res); }
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(); } } System.Reflection.MethodInfo mi = this.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(this.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 Microsoft.SPOT.Messaging.Message.RemotedException(ex); } try { message.Reply(res); } catch { } }