private static async Task ServerStreamingCallExample(Aggregator.AggregatorClient client)
        {
            var cts = new CancellationTokenSource();

            cts.CancelAfter(TimeSpan.FromSeconds(3.5));

            using var call = client.SayHellos(new HelloRequest { Name = "AggregatorClient" }, cancellationToken: cts.Token);
            try
            {
                await foreach (var message in call.ResponseStream.ReadAllAsync())
                {
                    Console.WriteLine("Greeting: " + message.Message);
                }
            }
            catch (RpcException ex) when(ex.StatusCode == StatusCode.Cancelled)
            {
                Console.WriteLine("Stream cancelled.");
            }
        }
Пример #2
0
        private static async Task ServerStreamingCallExample(Aggregator.AggregatorClient client)
        {
            var cts = new CancellationTokenSource();

            cts.CancelAfter(TimeSpan.FromSeconds(3.5));

            using (var replies = client.SayHellos(new HelloRequest {
                Name = "AggregatorClient"
            }, cancellationToken: cts.Token))
            {
                try
                {
                    while (await replies.ResponseStream.MoveNext(cts.Token))
                    {
                        Console.WriteLine("Greeting: " + replies.ResponseStream.Current.Message);
                    }
                }
                catch (RpcException ex) when(ex.StatusCode == StatusCode.Cancelled)
                {
                    Console.WriteLine("Stream cancelled.");
                }
            }
        }
Пример #3
0
        public static async Task AggregatorServerStreamingCallExample(Aggregator.AggregatorClient client)
        {
            var cts = new CancellationTokenSource();

            cts.CancelAfter(TimeSpan.FromSeconds(3.0));

            using (var replies = client.SayHellos(new HelloRequest {
                Name = "张三"
            }, cancellationToken: cts.Token))
            {
                try
                {
                    await foreach (var reply in replies.ResponseStream.ReadAllAsync())
                    {
                        Console.WriteLine($"Greeting:{reply.Message}");
                    }
                }
                catch (RpcException ex) when(ex.StatusCode == StatusCode.Cancelled)
                {
                    Console.WriteLine("Stream cancelled.");
                }
            }
        }