我正在尝试从 C# 客户端连接到 Go GRPC 服务器,但客户端通道无法连接到服务器。我希望连接到由 Go 编写和托管的 GRPC 服务器和用 C# 编写的客户端应该没有问题。我的 Go Server 连接是这样设置的:lis, err := net.Listen("tcp", ":50051")if err != nil {    log.Fatalf("Failed to listen: %v", err)}s := grpc.NewServer()pb.Register**ServiceServer(s, &server{})reflection.Register(s)if err := s.Serve(lis); err != nil {    log.Fatalf("Failed to serve: %v", err)}这是相当标准的,我知道我的服务器正在工作,因为我能够使用提供的端口与 Go 客户端连接:conn, err := grpc.Dial("localhost:50051", grpc.WithInsecure(), grpc.WithBlock())但是,当我尝试使用 C# 客户端使用Grpc.Net.Client包进行连接时,如下所示:var channel = GrpcChannel.ForAddress(@"http://localhost:50051", new GrpcChannelOptions{   Credentials = ChannelCredentials.Insecure});我得到一个Grpc.Core.RpcException: 'Status(StatusCode=Internal, Detail="Bad gRPC response. Response protocol downgraded to HTTP/1.1.")'例外。或者通过Grpc.Core这样使用包:var channel = new Channel("localhost:50051", ChannelCredentials.Insecure);导致Grpc.Core.RpcException: 'Status(StatusCode=Unavailable, Detail="failed to connect to all addresses")'异常。我已经在 C# 客户端中尝试了设置和不Http2UnencryptedSupport设置的两种方法,但我对为什么无法连接没有任何想法。任何关于我哪里出错的建议将不胜感激。
                    
                    
                1 回答
 
                    
                    
                            幕布斯6054654
                            
                                
                            
                        
                        
                                                
                    TA贡献1876条经验 获得超7个赞
对于 .NET 3.x,设置:
AppContext.SetSwitch( "System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
并http用于 URL 中的协议。
对于 .NET 5.0,使用Grpc.Net.Client版本 2.32.0 或更高版本。
- 1 回答
- 0 关注
- 359 浏览
添加回答
举报
0/150
	提交
		取消
	