Пример #1
0
        private static async Task GreeterRequestWithSecureChannel(GrpcChannel channel)
        {
            var client = new GreeterClient(channel);
            var reply  = await client.SayHelloAsync(new HelloRequest { Name = "GreeterClient" });

            Console.WriteLine("Greeting: " + reply.Message);
        }
        public async Task <IActionResult> OnPostAsync()
        {
            await _greeterClient.SayHelloAsync(new Api.HelloRequest {
                Name = Name
            });

            return(RedirectToPage("/Greetings/List"));
        }
Пример #3
0
        private static async Task GreeterRequest(GrpcChannel channel)
        {
            var client = new GreeterClient(channel);
            var reply  = await client.SayHelloAsync(new HelloRequest { Name = "GreeterClient" });

            Console.WriteLine("Greeting: " + reply.Message);
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
Пример #4
0
        private static async Task GreeterRequest(GrpcChannel channel, string token)
        {
            var headers = new Metadata();

            headers.Add("Authorization", $"Bearer {token}");

            var client = new GreeterClient(channel);
            var reply  = await client.SayHelloAsync(new HelloRequest { Name = "GreeterClient" }, headers);

            Console.WriteLine("Greeting: " + reply.Message);
        }
Пример #5
0
        public async Task <StringMessage> ClientTest(EmptyMessage request, ServerCallContext context)
        {
            var result = await _greeterClient.SayHelloAsync(new Helloworld.HelloRequest()
            {
                Name = "yilei"
            });

            return(new StringMessage()
            {
                Value = $"{result.Message},guid {_testScope.Id} "
            });
        }
Пример #6
0
        private static async Task GreeterRequestInsecure(GrpcChannel channel)
        {
            try
            {
                var client = new GreeterClient(channel);
                var reply  = await client.SayHelloAsync(new HelloRequest { Name = "GreeterClient" });

                Console.WriteLine("Greeting: " + reply.Message);
            }
            catch (Grpc.Core.RpcException ex) when(ex.StatusCode == StatusCode.Unauthenticated)
            {
                Console.WriteLine("Failed to make insecure Call to secure endpoint. Thats good! :)");
            }
        }
Пример #7
0
        static async Task Main(string[] args)
        {
            using var channel = GrpcChannel.ForAddress("https://localhost:5001/");
            var client = new GreeterClient(channel);


            var request = new HelloRequest
            {
                Name = "Pedro"
            };

            var response = await client.SayHelloAsync(request);

            Console.WriteLine(response.Message);
            Console.ReadKey();
        }
Пример #8
0
        static async Task Main(string[] args)
        {
            try
            {
                var channel = GrpcChannel.ForAddress("https://localhost:5001");
                var client  = new GreeterClient(channel);
                var reply   = await client.SayHelloAsync(new HelloRequest { Name = "Ian" });

                Console.WriteLine(reply.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.InnerException);
            }

            Console.ReadLine();
        }
Пример #9
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapGet("/", async context =>
                {
                    GreeterClient client = context.RequestServices.GetService <GreeterClient>();
                    HelloRequest request = new HelloRequest();
                    request.Name         = "Charles";
                    var reply            = await client.SayHelloAsync(request);

                    await context.Response.WriteAsync(reply.Message);
                });
            });
        }
Пример #10
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);

                try
                {
                    var reply = await _grpcClient.SayHelloAsync(new HelloRequest { Name = "GrpcClient" });

                    Console.WriteLine("Greeting: " + reply.Message);
                }
                catch (RpcException ex)
                {
                    _logger.LogError($"RpcException: {ex}");
                }
                catch (Exception ex)
                {
                    _logger.LogError($"Exception: {ex}");
                }

                await Task.Delay(TimeSpan.FromSeconds(5), stoppingToken);
            }
        }
Пример #11
0
        private static async Task <string> GetHello(GreeterClient client)
        {
            var response = await client.SayHelloAsync(new CommonRequest { Name = "GreeterClient" });

            return(response.Message);
        }
 public async Task SayHello()
 {
     var reply = await client.SayHelloAsync(new HelloRequest { Name = "World" });
 }