小编Sab*_*tha的帖子

Grpc .Net 客户端无法使用 SSL 连接到服务器

无法连接到此链接中提到的迎宾 grpc 服务 - https://docs.microsoft.com/en-us/aspnet/core/tutorials/grpc/grpc-start?view=aspnetcore-3.0 从迎宾客户端是使用 grpc.core 库(Grpc.Core.2.24.0Grpc.Core.Api.2.24.0)从 .net 框架应用程序编写。

下面是我的客户端代码。它适用于非 SSL,但不适用于 SSL

具有非 SSL 的客户端代码(这有效)

var channel = new Channel("localhost:5000", ChannelCredentials.Insecure);
var client = new Greeter.GreeterClient(channel);
var reply = await client.SayHelloAsync(new HelloRequest { Name = "GreeterClient" });
channel.ShutdownAsync().Wait();
Run Code Online (Sandbox Code Playgroud)

带有 SSL 的客户端代码(无法连接)

SslCredentials secureChannel = new SslCredentials();
var channel = new Channel("localhost", 5001, secureChannel);
var client = new Greeter.GreeterClient(channel);
var reply = await client.SayHelloAsync(new HelloRequest { Name = "GreeterClient" });
channel.ShutdownAsync().Wait();
Run Code Online (Sandbox Code Playgroud)

我使用 SSL 遇到的错误是:

Grpc.Core.RpcException: 'Status(StatusCode=Unavailable, …

c# grpc

3
推荐指数
1
解决办法
5588
查看次数

标签 统计

c# ×1

grpc ×1