Exemplo n.º 1
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Hello gRPC streaming Demo! \n");
            // This switch must be set before creating the GrpcChannel/HttpClient.
            AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
            using var channel = GrpcChannel.ForAddress("http://localhost:5000");
            var client = new Greeter.GreeterClient(channel);

            var token = new CancellationTokenSource(TimeSpan.FromSeconds(5));

            using var greetings = client.GetGreeting(new Empty(),
                                                     cancellationToken: token.Token);
            try
            {
                await foreach (var item in greetings.ResponseStream.ReadAllAsync(token.Token))
                {
                    Console.WriteLine(item.ToString());
                }
            }
            catch (RpcException exc)
            {
                Console.WriteLine(exc.Message);
            }
            // var reply = await client.GetGreeting(
            //                   new GrpcGreeting.GreetingRequest { Country = "INDIA" });

            // Console.WriteLine(reply.Message);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            //Using Google's grpc.core
            EnableGoogleGrpcLogging();

            var channel = new Channel("localhost:5001", ChannelCredentials.Insecure);  // Without TLS
            //var channel = new Grpc.Core.Channel("localhost:5001", new SslCredentials());  // With TLS
            var client = new Greeter.GreeterClient(channel);

            // Service call
            var helloResponse = client.GetGreeting(new HelloRequest {
                Name = "Leeroy Jenkins"
            });

            Console.WriteLine($"Response from GreeterService: {helloResponse.Message}");

            Console.WriteLine("Press any key ...");
            Console.ReadKey();
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            // Using Microsoft's Grpc.Net
            var loggerFactory = LoggerFactory.Create(logging =>
            {
                logging.AddConsole();
                logging.SetMinimumLevel(LogLevel.Debug);
            });

            using var channel = GrpcChannel.ForAddress("https://localhost:5001",
                                                       new GrpcChannelOptions { LoggerFactory = loggerFactory });

            var client = new Greeter.GreeterClient(channel);

            // Service call
            var helloResponse = client.GetGreeting(new HelloRequest {
                Name = "Leeory Jenkins"
            });

            Console.WriteLine($"Response from GreeterService: {helloResponse.Message}");

            Console.WriteLine("Press any key ...");
            Console.ReadKey();
        }