Ejemplo n.º 1
0
        internal static async Task ClientStreamingRequestExampleAsync(IGreetingClient client)
        {
            Console.WriteLine("Calling client streaming");
            var call          = client.GreetingService.ClientStreaming();
            var requestStream = call.RequestStream;

            while (true)
            {
                Console.Write("> Enter next name to send\n> or empty line to complete request stream: ");
                var name = Console.ReadLine();
                if (string.IsNullOrEmpty(name))
                {
                    break;
                }
                var request = new GreetingRequest {
                    Name = name
                };
                Console.WriteLine("Sending: {0}", name);
                await requestStream.WriteAsync(request);
            }
            Console.WriteLine("Completing request stream");
            requestStream.TryComplete();
            var response = await call.ResponseAsync;

            Console.WriteLine("Received response: {0}", response.Greeting);
        }
Ejemplo n.º 2
0
        internal static async Task UnaryRequestExampleAsync(IGreetingClient client)
        {
            Console.Write("> Enter name to send: ");
            var name    = Console.ReadLine();
            var request = new GreetingRequest {
                Name = name
            };

            Console.WriteLine("Sending: {0}", name);
            var response = await client.GreetingService.Unary(request);

            Console.WriteLine("Received: {0}", response.Greeting);
        }
Ejemplo n.º 3
0
        internal static async Task ServerStreamingRequestExampleAsync(IGreetingClient client)
        {
            Console.Write("> Enter name to send: ");
            var name    = Console.ReadLine();
            var request = new GreetingRequest {
                Name = name
            };

            Console.WriteLine("Sending: {0}", name);
            var responseStream = client.GreetingService.ServerStreaming(request).ResponseStream;

            while (await responseStream.WaitReadAvailableAsync())
            {
                while (responseStream.TryRead(out var response))
                {
                    Console.WriteLine("Received: {0}", response.Greeting);
                }
            }
            Console.WriteLine("Server stream completed");
        }
Ejemplo n.º 4
0
        internal static async Task DiscoveryExampleAsync(IGreetingClient client)
        {
            Console.WriteLine("Calling discovery for method {0}", GreetingService.DefaultDescriptor.UnaryMethod);
            var discoveredProviders = (await client.DiscoveryInvoker.DiscoverAsync(GreetingService.DefaultDescriptor.UnaryMethod)).ToArray();

            Console.WriteLine("Discovered {0} actions:", discoveredProviders.Length);
            for (var i = 0; i < discoveredProviders.Length; i++)
            {
                Console.WriteLine("  {0}: {1} ({2})", i, discoveredProviders[i].Title, discoveredProviders[i].ProvidedMethod.ProvidedService.ApplicationId);
            }
            while (true)
            {
                Console.WriteLine("> Please choose which one to invoke\n> or empty line to skip invocation: ");
                var s = Console.ReadLine();
                if (string.IsNullOrEmpty(s))
                {
                    break;
                }
                if (!int.TryParse(s, out var index) || index < 0 || index > discoveredProviders.Length)
                {
                    Console.WriteLine("Invalid input. Please try again.");
                }
                var provider = discoveredProviders[index];
                Console.WriteLine("Invoking {0} ({1})", provider.Title, provider.ProvidedMethod.ProvidedService.ApplicationId);
                Console.Write("> Enter name to send: ");
                var name    = Console.ReadLine();
                var request = new GreetingRequest {
                    Name = name
                };
                Console.WriteLine("Sending: {0}", name);
                var response = await client.CallInvoker.Call(provider, request);

                Console.WriteLine("Received: {0}", response.Greeting);
                break;
            }
        }