private static async Task BiDirectionalStreaming(TestService.TestServiceClient client) { using var call = client.BiDirectionalStreaming(); Console.WriteLine("Starting background task to receive messages"); var readTask = Task.Run(async() => { await foreach (var response in call.ResponseStream.ReadAllAsync()) { Console.WriteLine(response.Message); } // Echo messages sent to the service }); Console.WriteLine("Starting to send messages"); Console.WriteLine("Type a message to echo then press enter."); while (true) { var result = Console.ReadLine(); if (string.IsNullOrEmpty(result)) { break; } await call.RequestStream.WriteAsync(new HelloRequest() { Name = result }); } Console.WriteLine("Disconnecting"); await call.RequestStream.CompleteAsync(); await readTask; }