コード例 #1
0
            public override IMessage Invoke(IMessage message)
            {
                IMethodMessage myMethodMessage = (IMethodMessage)message;

                if (myMethodMessage.MethodSignature is Array)
                {
                    foreach (Type t in (Array)myMethodMessage.MethodSignature)
                    {
                        if (t.IsByRef)
                        {
                            throw new NotSupportedException("ByRef parameters are not supported");
                        }
                    }
                }

                MethodInfo mi = myMethodMessage.MethodBase as MethodInfo;

                if (mi != null)
                {
                    BinaryFormatter.PopulateFromType(mi.ReturnType);
                }

                MessageCall call = MessageCall.CreateFromIMethodMessage(myMethodMessage);

                object returnValue = m_from.SendMessage(m_to, 60 * 1000, call);

                // Build the return message to pass back to the transparent proxy.
                return(new ReturnMessage(returnValue, null, 0, null, (IMethodCallMessage)message));
            }
コード例 #2
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
            {
            }
        }
コード例 #3
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);
        }
コード例 #4
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);

            Microsoft.SPOT.Messaging.Message.RemotedException ex = o as Microsoft.SPOT.Messaging.Message.RemotedException;

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

            return o;
        }