private static async Task Average(Channel channel) { Console.WriteLine("Average client stream"); var averageClient = new AverageService.AverageServiceClient(channel); var averageStream = averageClient.Average(); foreach (int i in Enumerable.Range(1, 10)) { await averageStream.RequestStream.WriteAsync(new AverageRequest() { Number = new AverageNumber() { A = i } }); } await averageStream.RequestStream.CompleteAsync(); var averageResponse = await averageStream.ResponseAsync; Console.WriteLine(averageResponse.Result); }
static async Task Main(string[] args) { Channel channel = new Channel(target, ChannelCredentials.Insecure); await channel.ConnectAsync().ContinueWith((task) => { if (task.Status == TaskStatus.RanToCompletion) { Console.WriteLine("The client connected successfully"); } }); var client = new AverageService.AverageServiceClient(channel); var stream = client.ComputeAverage(); foreach (int number in Enumerable.Range(1, 4)) { var request = new AverageRequest() { Number = number }; await stream.RequestStream.WriteAsync(request); } await stream.RequestStream.CompleteAsync(); var response = await stream.ResponseAsync; Console.WriteLine(response.Result); channel.ShutdownAsync().Wait(); Console.ReadKey(); }
static async Task Main(string[] args) { var target = "localhost:50055"; Thread.Sleep(1000); Channel channel = new Channel(target, ChannelCredentials.Insecure); await channel.ConnectAsync().ContinueWith((task) => { if (task.Status == TaskStatus.RanToCompletion) { Console.WriteLine("The Client connected successfully"); } else { Console.WriteLine($"Client Task Status: {task.ToString()}"); } }); //var client = AverageService.AverageServiceClient(); var client = new AverageService.AverageServiceClient(channel); int[] numbers = { 1, 3, 7, 9, 11 }; var stream = client.ComputeAverage(); foreach (int i in numbers) { var request = new AverageRequest() { Number = i }; await stream.RequestStream.WriteAsync(request); } await stream.RequestStream.CompleteAsync(); var response = await stream.ResponseAsync; Console.WriteLine($"ComputedAverage is: {Environment.NewLine} {response.Average}"); channel.ShutdownAsync().Wait(); Console.ReadKey(); }