Exemple #1
0
        static async Task Main(string[] args)
        {
            var channel = new Channel("127.0.0.1:50052", ChannelCredentials.Insecure);

            var operands = new Operands()
            {
                Operand1 = 1, Operand2 = 2
            };
            var client = new Calculator.CalculatorClient(channel);

            var result = await client.AddAsync(operands);

            Console.WriteLine(result.Number_);
        }
        static async Task Main()
        {
            AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);

            var channel = GrpcChannel.ForAddress("http://localhost:10042");
            var calc    = new Calculator.CalculatorClient(channel);

            for (int i = 0; i < 5; i++)
            {
                using var ma = calc.MultiplyAsync(new MultiplyRequest { X = i, Y = i });
                var calcResult = await ma.ResponseAsync;
                Console.WriteLine(calcResult.Result);
            }

            var clock = new TimeService.TimeServiceClient(channel);

            using var subResult = clock.Subscribe(new Empty());
            var reader = subResult.ResponseStream;

            while (await reader.MoveNext(default))
        static async Task Main()
        {
            var channel = new Channel("localhost", 10042, ChannelCredentials.Insecure);

            try
            {
                var calc = new Calculator.CalculatorClient(channel);
                for (int i = 0; i < 5; i++)
                {
                    using var ma = calc.MultiplyAsync(new MultiplyRequest { X = i, Y = i });
                    var calcResult = await ma.ResponseAsync;
                    Console.WriteLine(calcResult.Result);
                }



                var clock = new TimeService.TimeServiceClient(channel);
                using var subResult = clock.Subscribe(new Empty());
                using var reader    = subResult.ResponseStream;
                while (await reader.MoveNext(default))
Exemple #4
0
        static async Task Main(string[] args)
        {
            Grpc.Core.Channel channel = new Grpc.Core.Channel("127.0.0.1:30051", Grpc.Core.ChannelCredentials.Insecure);

            var client = new Calculator.CalculatorClient(channel);

            var request = new IntegerMessage {
                Value = 56, Message = "Hello Grpc World"
            };

            Console.WriteLine($"Request: Value = {request.Value}, Message = {request.Message}");
            var reply = client.AddOne(request);

            Console.WriteLine($"Reply: Value = {reply.Value}, Message = {reply.Message}");

            await channel.ShutdownAsync();

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