示例#1
0
        internal object InvokeMethod(string channelName, string methodName, int methodIndex, object[] args, Type returnType)
        {
            var data = MessageFormatter.FromChannelMethodInvoke(channelName, methodIndex, args);
            var head = new byte[17];

            head[0] = 3;
            var id = Guid.NewGuid();

            id.ToByteArray().CopyTo(head, 1);
            ServiceContext.Current.User.Client.Send(data, head);
            IOManager.BeginMessage(id);
            object result;
            string errorMsg;

            MessageFormatter.ToChannelMethodResult(IOManager.EndMessage(id), returnType, out result, out errorMsg);
            if (errorMsg == null)
            {
                return(result);
            }

            switch (errorMsg)
            {
            case "ChannelNotExist":
                throw new ChannelNotExistException(channelName, ServiceContext.Current.User.Client.EndPoint);

            case "MethodNotExist":
                throw new MethodNotExistException(channelName, methodName, ServiceContext.Current.User.Client.EndPoint);

            case "MethodParametersError":
                throw new MethodParamaterException(channelName, methodName, ServiceContext.Current.User.Client.EndPoint, args);

            case "MethodRuntimeError":
                throw new MethodRuntimeException(channelName, methodName, ServiceContext.Current.User.Client.EndPoint);
            }
            return(null);
        }