dotnet framework4.5.2调用dotnetcore grpc

创建GPRC项目

dotnet framework4.5.2调用dotnetcore grpc

 

 运行

新建dotnet framework 4.5.2的winform项目

dotnet framework4.5.2调用dotnetcore grpc

 

 dotnet framework4.5.2调用dotnetcore grpc

 

 添加nuget包,Google.Protobuf  Grpc.Tools  Grpc.Core,然后把服务端的proto文件复制到winform项目里面

dotnet framework4.5.2调用dotnetcore grpc

 

 更改proto文件的属性

dotnet framework4.5.2调用dotnetcore grpc

 

 添加控件到窗体上

dotnet framework4.5.2调用dotnetcore grpc

 

 添加按钮点击事件

 private void button1_Click(object sender, EventArgs e)
        {
            var channel = new Channel("localhost", 5001, ChannelCredentials.Insecure);
            var client = new Greeter.GreeterClient(channel);
            var reply = client.SayHelloAsync(
                new HelloRequest { Name = "李德镇" }).GetAwaiter().GetResult();
            MessageBox.Show("Greeting: " + reply.Message);
        }

这个时候运行程序客户端会报错 Grpc.Core.RpcException:“Status(StatusCode="Unavailable", Detail="failed to connect to all addresses", 

dotnet framework4.5.2调用dotnetcore grpc

 

 这个是因为 服务端是https 而客户端是用http协议来调用的,所以才会出现错误,解决方法:

修改服务端的program文件  用5000端口

dotnet framework4.5.2调用dotnetcore grpc

 

 更改后

dotnet framework4.5.2调用dotnetcore grpc

 

 客户端也改成5000端口,运行服务端和客户端

dotnet framework4.5.2调用dotnetcore grpc

 

 调用成功

 

上一篇:lombok-@NoArgsConstructor @AllArgsConstructor


下一篇:DotNetCore笔记-nginx代理访问swagger