c#使用grpc
2017-04-08 19:18
127 查看
static readonly Marshaller<string> _marshaller = new Marshaller<string>(p => Encoding.UTF8.GetBytes(p), p => Encoding.UTF8.GetString(p)); ///服务端 var server = new Server(); server.Ports.Add(new ServerPort("127.0.0.1", 12345, ServerCredentials.Insecure)); var s = ServerServiceDefinition.CreateBuilder(); s.AddMethod(new Method<string, string>(MethodType.Unary, "service", "say", _marshaller, _marshaller), new UnaryServerMethod<string, string>((request, context) => Task.FromResult(request + "_" + DateTime.Now.ToString()))); server.Services.Add(s.Build()); server.Start(); Console.ReadLine(); server.ShutdownAsync().Wait(); ///客户端 Channel channel = new Channel("127.0.0.1", 12345, ChannelCredentials.Insecure); var client = new Client(channel); Console.WriteLine(client.say("===========")); channel.ShutdownAsync().Wait(); public class Client : ClientBase { public Client(Channel channel) : base(channel) { this.Channel = channel; } public Channel Channel; public string say(string str) { return this.CallInvoker.BlockingUnaryCall<string, string>(_Method, null, new CallOptions(), str); } static readonly Method<string, string> _Method = new Method<string, string>(MethodType.Unary, "service", "say", _marshaller, _marshaller); }
相关文章推荐
- C# 使用 grpc
- gRPC在c#中的使用(服务端)
- C#中使用gRPC
- C#中使用gRPC
- 在C#中使用gRPC及protobuf简介
- 初识google多语言通信框架gRPC系列(三)C#中使用gRPC
- C# Builder 使用心得
- C#中事件的使用
- 如何在C#中使用 Win32和其他库
- 开始使用C#
- 磁盘配额的WMI版本(还是使用C#)
- 源码推荐:一个使用C#绘制图形引擎的Framework
- 你还在为使用P/Invoke时,写不出win32 api对应的C#声明而犯愁吗?
- 在WinForm中使用Web Services 来实现 软件 自动升级( Auto Update ) (C#) skyover [原作]
- C#中使用Property Grid 控件 学习笔记(一)
- 使用C#+ASP.NET来进行RSA(非对称)加密.
- 使用C#开发一个简单的P2P应用
- 使用C#制作的更换桌面背景程序
- 如何使用C#创建一个三层的数据库应用程序
- C# Builder 使用心得