static async Task Main(string[] args) { //http1方式要加下面这个段,不然有异常 AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);//使用HTTP方式 //服务端地址 using var channel = GrpcChannel.ForAddress("http://localhost:50051"); var client = new Greeter.GreeterClient(channel); var reply = await client.SayHelloAsync( new HelloRequest { Name = "GreeterClient123" }); var reply1 = await client.GetNameAsync(new HelloRequest { Name = "我是谁?" }); Console.WriteLine(); Console.WriteLine("Greeting: " + reply.Message); Console.WriteLine(); Console.WriteLine("回复:" + reply1.Message); Console.WriteLine(); Console.WriteLine("Press any key to exit..."); Console.ReadKey(); await run1(); }