Пример #1
0
        public JsonResult Get(int id)
        {
            var reqUserId = new RequestUserId
            {
                Id = id
            };
            var person = _personInfoService.GetPersonInfoById(reqUserId, null);

            return(new JsonResult(person));
        }
        public override Task <ResponseUserInfo> GetPersonInfoById(RequestUserId request, ServerCallContext context)
        {
            var list       = new PersonRepository().GetAllPersons().Result.Person;
            var currPerson = list.FirstOrDefault(p => p.Id == request.Id);

            return(Task.FromResult(new ResponseUserInfo
            {
                Person = currPerson
            }));
        }
        public JsonResult Get(int id)
        {
            RequestUserId req = new RequestUserId {
                Id = id
            };
            var person = _personService.GetPersonInfoById(req, null);

            //string outStr = JsonConvert.SerializeObject(person);

            return(new JsonResult(person));
        }
Пример #4
0
        static void Main(string[] args)
        {
            #region  务实现

            HelloRequest request = new HelloRequest();
            request.Name = "Simon";

            var reply = new GreeterService(_logger).SayHello(request, null);
            Console.WriteLine("服务1:");
            Console.WriteLine("Grpc ServerListening On Port 5001,Out put:" + reply.Result.Message);//Grpc ServerListening On Port 8088,Out put:Hello Simon
            #endregion

            #region Demo 服务实现

            ResponseModel respModel = new ResponseModel();
            respModel.Id   = 2;
            respModel.Name = "Acadsoc";

            var resp = new DemoService().DemoMethod(null, null);
            Console.WriteLine("服务2:根据获取名称");
            Console.WriteLine(resp.Result);

            #endregion

            #region 获取人员信息


            RequestUserId uid = new RequestUserId {
                Id = 2
            };
            var person = new PersonInfoService().GetPersonInfoById(uid, null);
            Console.WriteLine("服务3:根据ID获取对象信息");
            Console.WriteLine("获取用户信息为:" + JsonConvert.SerializeObject(person));

            // 获取用户信息为:{ "Result":{ "Person":{ "Id":2,"Name":"Lily","Age":30,"Gender":1,"Weight":158.5,"EmailVerified":false,"Phone":[],"Salary":3200.0,"MyAdd":[]} },"Id":1,"Exception":null,"Status":5,"IsCanceled":false,"IsCompleted":true,"IsCompletedSuccessfully":true,"CreationOptions":0,"AsyncState":null,"IsFaulted":false}

            #endregion

            Console.WriteLine("任意键退出...");
            Console.ReadKey();
        }
Пример #5
0
 /// <summary>
 /// 根据用户Id 获取用户对象
 /// </summary>
 /// <param name="userId"></param>
 /// <returns></returns>
 public async Task <ResponseUserInfo> GetUserInfoById(RequestUserId userId)
 {
     return(await _client.GetPersonInfoByIdAsync(userId));
 }