示例#1
0
        public static async Task DoLongGreet(GreetingService.GreetingServiceClient client)
        {
            var greeting = new Greeting()
            {
                FirstName = "Clement",
                LastName  = "Jean"
            };

            var request = new LongGreetRequest()
            {
                Greeting = greeting
            };
            var stream = client.LongGreet();

            foreach (int i in Enumerable.Range(1, 10))
            {
                await stream.RequestStream.WriteAsync(request);
            }

            await stream.RequestStream.CompleteAsync();

            var response = await stream.ResponseAsync;

            Console.WriteLine(response.Result);
        }
示例#2
0
        private static async Task LongGreetClientStream(Channel channel)
        {
            Console.WriteLine("Long greet client stream");
            var client = new GreetingService.GreetingServiceClient(channel);

            var greeting = new Greeting()
            {
                FirstName = "Stanislaw",
                LastName  = "Banski"
            };

            var longRequest = new LongGreetRequest()
            {
                Greeting = greeting
            };
            var stream = client.LongGreet();

            foreach (int i in Enumerable.Range(1, 10))
            {
                await stream.RequestStream.WriteAsync(longRequest);
            }

            await stream.RequestStream.CompleteAsync();

            var longResponse = await stream.ResponseAsync;

            Console.WriteLine(longResponse.Result);
        }
示例#3
0
        static async Task ClientStreaming(Channel channel)
        {
            WriteHeader("ClientStreaming");
            var clientStreamingClient  = new GreetingService.GreetingServiceClient(channel);
            var clientStreamingRequest = new LongGreetRequest {
                Greeting = "hello"
            };
            var clientStreamingStream = clientStreamingClient.LongGreet();

            for (var i = 0; i < 10; i++)
            {
                await clientStreamingStream.RequestStream.WriteAsync(clientStreamingRequest);
            }
            await clientStreamingStream.RequestStream.CompleteAsync();

            var clientStreamingResponse = await clientStreamingStream.ResponseAsync;

            Console.WriteLine($"client streaming: {clientStreamingResponse.Result}");
        }
示例#4
0
        private static async Task LongGreet(GreetingService.GreetingServiceClient greetingClient)
        {
            var greeting = new Greeting()
            {
                FirstName = "Kevin Hayes",
                LastName  = "Anderson"
            };
            var longGreetRequest = new LongGreetRequest()
            {
                Greeting = greeting
            };
            var longStream = greetingClient.LongGreet();

            foreach (var i in Enumerable.Range(1, 10))
            {
                await longStream.RequestStream.WriteAsync(longGreetRequest);
            }
            await longStream.RequestStream.CompleteAsync();

            var longGreetResponse = await longStream.ResponseAsync;

            Console.WriteLine(longGreetResponse.Result);
        }