五、
生成DotNetClient
通过Nuget安装Grpc、Grpc.Core及Google.Protobuf
将Helloworld.cs及HelloworldGrpc.cs文件添加到项目中。
编辑Program.cs如下所示:
using System;
using Grpc.Core;
using Helloworld;
namespace DotNetClient
{
class Program
{
static void Main(string[] args)
{
Channel channel = new Channel("127.0.0.1:50051", ChannelCredentials.Insecure);
var client = new Greeter.GreeterClient(channel);
var reply = client.SayHello(new HelloRequest { Name = "tom" });
Console.WriteLine("Greeting: " + reply.Message);
channel.ShutdownAsync().Wait();
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
}
}