首页 > 解决方案 > 尝试从 winforms 应用程序连接 GRPC 服务器时无法连接到所有地址异常

问题描述

你好grpc新手在这里,

我有一个要连接到 grpc 服务器的 winforms 应用程序。

我在 localhost 上运行 grpc 服务器并使用 winforms 应用程序连接到它没有问题。

我已经将我的 grpc 服务器部署到了一个临时 url:http ://mujf94-001-site1.gtempurl.com/

但是当我尝试连接它时,我收到以下错误:

Status(StatusCode="Unavailable", Detail="failed to connect to all addresses", 
DebugException="Grpc.Core.Internal.CoreErrorDetailException: 
{"created":"@1630271164.373000000","description":"Failed to pick 
subchannel","file":"..\..\..\src\core\ext\filters\client_channel\client_channel.cc",
"file_line":3009,"referenced_errors":[{"created":"@1630271164.373000000","description":
"failed to connect to all addresses","file":"..\..\..\src\core\ext\filters\client_channel\
lb_policy\pick_first\pick_first.cc","file_line":398,"grpc_status":14}]}")

这就是我尝试连接到 grpc 服务器的方式:

        var ip = "mujf94-001-site1.gtempurl.com".ToIPAddress();

        var channel = new Channel(ip.ToString(),80, ChannelCredentials.Insecure);

        //var channel = new Channel("http://mujf94-001-site1.gtempurl.com", 80, ChannelCredentials.Insecure);

        Client = channel.CreateGrpcService<T>();

我的 grpc 服务器选项是这样的:

public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
                webBuilder.ConfigureKestrel(options =>
                {
                    options.Listen("mujf94-001-site1.gtempurl.com".ToIPAddress(), 80, o => o.Protocols = HttpProtocols.Http2);
                });
                webBuilder.UseStartup<Startup>();
            });

我对此很陌生,所以非常感谢任何帮助

标签: c#protobuf-netgrpc-c#

解决方案


推荐阅读