Example #1
0
        public override Task <ProductModel> GetProductById(GetProductByIdModel request, ServerCallContext context)
        {
            var product = ProductData.ProductModels.Where(p => p.ProductId == request.ProductId).FirstOrDefault();

            if (product != null)
            {
                return(Task.FromResult(product));
            }
            else
            {
                return(null);
            }
        }
Example #2
0
        public override Task <ProductModel> GetProductById(GetProductByIdModel request, ServerCallContext context)
        {
            AsyncUnaryCall <SendOrderReply> a = _shipping.SendOrderAsync(new SendOrderRequest
            {
                Address   = "a",
                Quantity  = 2,
                OrderId   = "a12",
                ProductId = "P123"
            });
            var product = ProductData.ProductModels.Where(p => p.ProductId == request.ProductId).FirstOrDefault();

            if (product != null)
            {
                return(Task.FromResult(product));
            }
            else
            {
                return(null);
            }
        }
        static async Task Main(string[] args)
        {
            var data = new GetProductByIdModel {
                ProductId = 2
            };
            var grpcChannel = GrpcChannel.ForAddress("https://localhost:5001");
            var client      = new Product.ProductClient(grpcChannel);
            var response    = await client.GetProductByIdAsync(data);

            Console.WriteLine(response);
            Console.ReadLine();
            using (var clientData = client.GetAllProducts(new GetAllProductsRequest()))
            {
                while (await clientData.ResponseStream.MoveNext(new System.Threading.CancellationToken()))
                {
                    var thisProduct = clientData.ResponseStream.Current;
                    Console.WriteLine(thisProduct);
                }
            }
            Console.ReadLine();
        }
        static async Task Main(string[] args)
        {
            //var data = new HelloRequest { Name = "tonmoy" };
            //var grpcChannel = GrpcChannel.ForAddress("https://localhost:5001");
            //var client = new Greeter.GreeterClient(grpcChannel);
            //var response = await client.SayHelloAsync(data);
            //Console.WriteLine(response.Message);
            //Console.ReadLine();

            var data = new GetProductByIdModel {
                ProductId = 2
            };
            var grpcChannel = GrpcChannel.ForAddress("https://localhost:5001");
            var client      = new Product.ProductClient(grpcChannel);
            var response    = await client.GetProductByIdAsync(data);

            Console.WriteLine(response);

            //var data = new GetStudentByIdModel { StudentId = 2 };
            //var grpcChannel = GrpcChannel.ForAddress("https://localhost:5001");
            //var client = new Student.StudentClient(grpcChannel);
            //var response = await client.GetStudentByIdAsync(data);
            //Console.WriteLine(response);
        }