static async Task Main(string[] args) { AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); using var channel = GrpcChannel.ForAddress("http://localhost:5000", new GrpcChannelOptions() { HttpHandler = new Handler(new SocketsHttpHandler()), DisposeHttpClient = true, }); var client = new GrpcGreeter.Greeter.GreeterClient(channel); try { var name = args.Length == 1 ? args[0] : "Pranav"; var reply = await client.SayHelloAsync(new GrpcGreeter.HelloRequest { Name = name, }); Console.WriteLine("Greeting: " + reply.Message); } catch (RpcException ex) { Console.WriteLine($"Status Code: {ex.Status.StatusCode}"); Console.WriteLine($"Status Detail: {ex.Status.Detail}"); Console.WriteLine($"Trailer Count: {ex.Trailers.Count}"); foreach (var kvp in ex.Trailers) { Console.WriteLine($"Trailer: {kvp.Key}: {(kvp.IsBinary ? "(binary data)" : kvp.Value)}"); } } }
static async Task Main(string[] args) { Console.WriteLine("Hello World!"); using var channel = GrpcChannel.ForAddress("https://localhost:443"); var client = new GrpcGreeter.Greeter.GreeterClient(channel); for (int i = 0; i < 100_000_000; i++) { var reply = await client.SayHelloAsync( new HelloRequest { Name = $"GreeterClient {i}" }); Console.WriteLine("Greeting: " + reply.Message); } Console.WriteLine("Press any key to exit..."); Console.ReadKey(); }