【发布时间】:2020-08-07 22:40:06
【问题描述】:
我创建了一个 DotNet Core 3.1 gRPC 服务器。
是否可以在 DotNet Framework 4.8 客户端中使用此服务器?
我参考了这些包:
- Google.Protobuf
- Grpc.Core
- Grpc.Core.Api
我的测试代码如下所示:
using Grpc.Core;
using System;
using System.Windows.Forms;
namespace DotNetgRpcTest.ClientWinformC
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Channel channel = new Channel("127.0.0.1:50051", ChannelCredentials.Insecure);
var client = new Greeter.GreeterClient(channel);
String user = "John";
var reply = client.SayHello(new HelloRequest { Name = user });
Console.WriteLine("Greeting: " + reply.Message);
}
}
}
我已经从服务器复制了 greet.proto...
但是在上面的代码中找不到 Greeter。
真的可以吗?
更新.......
我设法用这些 nuget 将 Protos 放入 .Net Standard 2.0 库中:
- Grpc
- Grpc.Core
- Grpc.Tools
下一个问题...
当我运行应用程序时,我的 .Net Frmawork 4.8 应用程序给了我这个错误:
Grpc.Core.RpcException: 'Status(StatusCode=Unavailable, Detail="failed to connect to all addresses")'
从谷歌我了解到服务器中的这段代码可以修复它......
webBuilder.ConfigureKestrel(options =>
{
// This endpoint will use HTTP/2 and HTTPS on port 5001.
options.Listen(IPAddress.Any, 5001, listenOptions =>
{
listenOptions.Protocols = HttpProtocols.Http2;
});
});
它确实做到了 - 现在我的 .Net Framework 4.8 应用程序可以工作....但是现在我的 .Net Core 客户端应用程序给了我这个错误:
Grpc.Core.RpcException: 'Status(StatusCode=Internal, Detail="Error starting gRPC call: The SSL connection could not be established, see inner exception.")'
【问题讨论】: