Exemple #1
0
        public override async Task <OrderResponse> GetGoods(OrderRequest request, ServerCallContext context)
        {
            //怬
            var tokenResponse = await _client.LoginAsync(
                new LoginRequest()
            {
                Username = "******",
                Password = "******"
            });

            if (tokenResponse.Result)
            {
                var token   = $"Bearer {tokenResponse.Token }";
                var headers = new Metadata {
                    { "Authorization", token }
                };
                //²éѯ
                var query = await _client.GetGoodsAsync(
                    new QueryRequest { Name = "¹ðËØΰ" }, headers);

                Console.WriteLine($"·µ»ØÖµ  Name:{ query.Name},Quantity:{ query.Quantity}");
                return(new OrderResponse {
                    Name = query.Name, Quantity = query.Quantity
                });
            }
            else
            {
                Console.WriteLine("µÇ¼ʧ°Ü");
                return(null);
            }
        }
Exemple #2
0
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="token">token</param>
        /// <returns></returns>
        static async Task Query(string token)
        {
            token = $"Bearer {token }";
            var headers = new Metadata {
                { "Authorization", token }
            };
            var channel = GrpcChannel.ForAddress("https://localhost:5001");
            var client  = new Goodser.GoodserClient(channel);
            var query   = await client.GetGoodsAsync(
                new QueryRequest { Name = "桂素伟" }, headers);

            Console.WriteLine($"返回值  Name:{ query.Name},Quantity:{ query.Quantity}");
        }
Exemple #3
0
        public async Task <string> Get()
        {
            //登录
            var tokenResponse = await _client.LoginAsync(new LoginRequest { Username = "******", Password = "******" });

            var token   = $"Bearer {tokenResponse.Token }";
            var headers = new Metadata {
                { "Authorization", token }
            };
            var request = new QueryRequest {
                Name = "桂素伟"
            };
            //查询
            var query = await _client.GetGoodsAsync(request, headers);

            return($"Name:{query.Name},Quantity:{query.Quantity}");
        }