示例#1
0
        private static async Task Test5()
        {
            Channel channel = new Channel(target, ChannelCredentials.Insecure);

            await channel.ConnectAsync().ContinueWith(task =>
            {
                if (task.Status == TaskStatus.RanToCompletion)
                {
                    Console.WriteLine("Connected to the server");
                }
            });

            var client = new GreetingService.GreetingServiceClient(channel);

            var stream = client.GreetLong();

            for (int index = 0; index < 10; index++)
            {
                await stream.RequestStream.WriteAsync(new GreetingLongRequest
                {
                    Greeting = new Greeting
                    {
                        FirstName = $"Fred {index}",
                        LastName  = $"Seifi {index}"
                    }
                });
            }

            await stream.RequestStream.CompleteAsync();

            var response = await stream.ResponseAsync;

            Console.WriteLine($"here is the response : {response.Result}");
            await channel.ShutdownAsync();

            Console.ReadKey();
        }