Ejemplo n.º 1
0
        public RpcServer(IRpcService rpcService, string host = "*", int responsePort = -1) : base(responsePort, 0, host)
        {
            _rpcService = rpcService;

            foreach (var methodInfo in rpcService.GetType().GetMethods())
            {
                foreach (var attr in methodInfo.GetCustomAttributes(typeof(ServiceFuncAttribute)))
                {
                    var funcAttr = (ServiceFuncAttribute)attr;
                    var args = methodInfo.GetParameters();
                    var requestType = args[0].ParameterType;
                    var retType = methodInfo.ReturnType;

                    var info = new RpcServiceFuncInfo()
                    {
                        ArgType = requestType,
                        ReturnType = retType,
                        Method = methodInfo,
                    };
                    _serviceFuncs[requestType] = info;
                    Logger.Info("Register Service Func, RequestType: {0}, ResponseType: {1}", requestType, info.ReturnType);

                }
            }

            if (_serviceFuncs.Count <= 0)
            {
                Logger.Error("RpcServcice(Type:{0}), has no funcs mark with ServiceFuncAttribute", rpcService.GetType());
            }
        }
Ejemplo n.º 2
0
        public RpcServer(IRpcService rpcService, string host = "*", int responsePort = -1) : base(responsePort, 0, host)
        {
            _rpcService = rpcService;

            foreach (var methodInfo in rpcService.GetType().GetMethods())
            {
                foreach (var attr in methodInfo.GetCustomAttributes(typeof(ServiceFuncAttribute)))
                {
                    var funcAttr    = (ServiceFuncAttribute)attr;
                    var args        = methodInfo.GetParameters();
                    var requestType = args[0].ParameterType;
                    var retType     = methodInfo.ReturnType;

                    var info = new RpcServiceFuncInfo()
                    {
                        ArgType    = requestType,
                        ReturnType = retType,
                        Method     = methodInfo,
                    };
                    _serviceFuncs[requestType] = info;
                    Logger.Info("Register Service Func, RequestType: {0}, ResponseType: {1}", requestType, info.ReturnType);
                }
            }

            if (_serviceFuncs.Count <= 0)
            {
                Logger.Error("RpcServcice(Type:{0}), has no funcs mark with ServiceFuncAttribute", rpcService.GetType());
            }
        }