public static void Main(string[] args) { var channel = new Channel("127.0.0.1:5051", ChannelCredentials.Insecure); var client = new SimpleService.SimpleServiceClient(channel); var req = new SimpleRequestList(); var req_1 = new SimpleRequest(); req_1.Name = "ken"; req_1.Msg = "baka"; req.PersonList.Add(req_1); var req_2 = new SimpleRequest(); req_2.Name = "tom"; req_2.Msg = "aho"; req.PersonList.Add(req_2); var res = client.SimpleSend(req); foreach (var item in res.ResponseList) { Console.WriteLine(item.ReplyMsg); } }
/// <summary> /// 连接服务器 /// </summary> private void Connect() { string remoteAddr = remoteHost + ":" + remotePort; Channel channel = new Channel(remoteAddr, ChannelCredentials.Insecure); client = new SimpleService.SimpleServiceClient(channel); }
public void GlobalSetup() { var definitionsProvider = new RpcServiceDefinitionsBuilder(); switch (this.ConnectionType) { case RpcConnectionType.Grpc: this.server = new GrpcCore.Server { Services = { SimpleService.BindService(new GrpcSimpleService()) }, Ports = { new GrpcCore.ServerPort("localhost", 50051, GrpcCore.ServerCredentials.Insecure) } }; this.server.Start(); this.channel = new GrpcCore.Channel("127.0.0.1:50051", GrpcCore.ChannelCredentials.Insecure); this.clientService = new SimpleService.SimpleServiceClient(this.channel); break; #if COREFX case RpcConnectionType.NetGrpc: this.host = CreateNetGrpcHost(); host.Start(); var handler = new System.Net.Http.HttpClientHandler(); handler.ServerCertificateCustomValidationCallback = (httpRequestMessage, cert, cetChain, policyErrors) => { return(true); }; var channelOptions = new GrpcNet.Client.GrpcChannelOptions() { HttpClient = new System.Net.Http.HttpClient(handler), DisposeHttpClient = true }; this.channel = GrpcChannel.ForAddress("https://localhost:50051", channelOptions); this.clientService = new SimpleService.SimpleServiceClient(channel); break; #endif } }