4

我有以下问题。

我创建了一个 gRpc 服务器(控制台应用程序 .Net 4.7.2 - 由于 Crystal Reports :()和一个客户端(WPF App .Net Core 3.1),我无法在服务器端执行 Net Core,只要服务器和客户端在我的机器上(Windows 10)。就我将服务器带到另一台机器(Windows Server 2016)而言,它不再工作了。

这是 RPC 异常:

Status(StatusCode="Unavailable", Detail="未能连接到所有地址", DebugException="Grpc.Core.Internal.CoreErrorDetailException: {"created":"@1595508082.170000000","description":"无法选择子通道" "文件":"T:\src\github\grpc\workspace_csharp_ext_windows_x64\src\core\ext\filters\client_channel\client_channel.cc","file_line":3948,"referenced_errors":[{"created":"@ 1595508082.170000000","description":"连接所有地址失败","file":"T:\src\github\grpc\workspace_csharp_ext_windows_x64\src\core\ext\filters\client_channel\lb_policy\pick_first\pick_first.cc" ,"file_line":394,"grpc_status":14}]}")

我尝试了所有的变化。这是我在本地主机上工作的最后一个代码:

服务器:

static void Main(string[] args)
    {
        var cacert = File.ReadAllText(@"root.crt");
        var servercert = File.ReadAllText(@"server.crt");
        var serverkey = File.ReadAllText(@"server.key");
        var keypair = new KeyCertificatePair(servercert, serverkey);
        var sslCredentials = new SslServerCredentials(new List<KeyCertificatePair>() { keypair }, cacert, false);

        // Build a server
        var server = new Server
        {
            Services = { ReportService.BindService(new KKarteReportService()) },
            Ports = { new ServerPort(Host, Port, sslCredentials) }
        };


        // Start server
        server.Start();

        Console.WriteLine("KKarteReport Server listening on port " + Port);
        Console.WriteLine("Press any key to stop the server...");
        Console.ReadKey();

        server.ShutdownAsync().Wait();
    }

客户

var cacert = File.ReadAllText(@"root.crt");
var clientcert = File.ReadAllText(@"client.crt");
var clientkey = File.ReadAllText(@"client.key");
var ssl = new SslCredentials(cacert, new KeyCertificatePair(clientcert, clientkey));
           
 var options = new List<ChannelOption> { new ChannelOption(ChannelOptions.SslTargetNameOverride, "MyServerHost") }; 
 var channel = new Channel("12.20.18.11", 5001, ssl, options);
 //var channel = new Channel("localhost", 5001, ssl, options);
 //var channel = new Channel(url, ChannelCredentials.Insecure);
 var client = new ReportService.ReportServiceClient(channel);

  using var streamingCall = client.CreateAusschreibung(request);

  await using var ms = new MemoryStream();

  while (await streamingCall.ResponseStream.MoveNext())
  {
        ms.Write(streamingCall.ResponseStream.Current.FileChunk.ToByteArray());
  }

我想念什么?

4

1 回答 1

4

服务器端的“主机”变量包含什么?问题可能是地址绑定不正确,这会阻止从 localhost (127.0.0.1) 以外的 IP 地址访问服务。尝试在那里输入 0.0.0.0。

于 2020-07-27T22:00:27.170 回答