Ejemplo n.º 1
0
        static async Task Main(string[] args)
        {
            Channel channel = new Channel(target, ChannelCredentials.Insecure);
            await channel.ConnectAsync().ContinueWith((task) =>
            {
                if (task.Status == TaskStatus.RanToCompletion)
                {
                    Console.WriteLine("The Client Connected Successfully");
                }
            });

            var client = new SqrtService.SqrtServiceClient(channel);

            //int number = 16;//4
            int number = -1;//throws exception

            try
            {
                var response = client.sqrt(new SqrtRequest()
                {
                    Number = number
                });
                Console.WriteLine(response.SquareRoot);
            }
            catch (RpcException e)
            {
                Console.WriteLine("Error : " + e.Status.Detail);
            }


            channel.ShutdownAsync().Wait();
            Console.ReadKey();
        }
Ejemplo n.º 2
0
        public static void CalcSqrt(SqrtService.SqrtServiceClient client)
        {
            int number = -1;

            try
            {
                var response = client.sqrt(new SqrtRequest()
                {
                    Number = number
                });
                Console.WriteLine(response.SquareRoot);
            }
            catch (RpcException e)
            {
                Console.WriteLine("Error: {0}", e.Status.Detail);
            }
        }
Ejemplo n.º 3
0
        static async Task Main(string[] args)
        {
            const string target  = "127.0.0.1:50051";
            Channel      channel = new Channel(target, ChannelCredentials.Insecure);
            await channel.ConnectAsync().ContinueWith((task) =>
            {
                if (task.Status == TaskStatus.RanToCompletion)
                {
                    Console.WriteLine("The client connected sussesfully");
                }
            });


            var client = new SqrtService.SqrtServiceClient(channel);
            int number = -1;

            try
            {
                //var response = client.sqrt(new SqrtRequest() { Number = number });
                //deadline
                var response = client.sqrt(new SqrtRequest()
                {
                    Number = number
                },
                                           deadline: DateTime.UtcNow.AddMilliseconds(500));
                Console.WriteLine(response.SquareRoot);
            }
            catch (RpcException e) when(e.StatusCode == StatusCode.DeadlineExceeded)
            {
                Console.WriteLine("Error deadline : " + e.Status.Detail);
            }
            catch (RpcException e)
            {
                Console.WriteLine("Error : " + e.Status.Detail);
                throw;
            }



            channel.ShutdownAsync().Wait();
            Console.ReadKey();
        }
        static async Task Main(string[] args)
        {
            Channel channel = new Channel(target, ChannelCredentials.Insecure);

            await channel.ConnectAsync().ContinueWith((task) =>
            {
                if (task.Status == TaskStatus.RanToCompletion)
                {
                    Console.WriteLine("The client connected successfully");
                }
            });

            var client = new SqrtService.SqrtServiceClient(channel);
            int number = 16;

            try
            {
                var response = client.sqrt(new SqrtRequest()
                {
                    Number = number
                },
                                           deadline: DateTime.UtcNow.AddSeconds(1));

                Console.WriteLine(response.SquareRoot);
            }
            catch (RpcException e) when(e.StatusCode == StatusCode.InvalidArgument)
            {
                Console.WriteLine("Error : " + e.Status.Detail);
            }
            catch (RpcException e) when(e.StatusCode == StatusCode.DeadlineExceeded)
            {
                Console.WriteLine("Deadline exceeded !");
            }

            channel.ShutdownAsync().Wait();
            Console.ReadKey();
        }