Ejemplo n.º 1
0
        public static async Task Main(string[] args)
        {
            var    loggerFactory = new LoggerFactory().AddConsole();
            Tracer tracer        = TracingHelper.InitTracer("client", loggerFactory);
            ClientTracingInterceptor tracingInterceptor = new ClientTracingInterceptor(tracer);


            Channel channel = new Channel($"{Server}:{Port}", ChannelCredentials.Insecure);

            var    client = new gRPCService.gRPCServiceClient(channel.Intercept(tracingInterceptor));
            string user   = "******";

            var reply = client.SayHello(new HelloRequest {
                Name = user, SendDate = DateTime.UtcNow.ToTimestamp()
            });

            Console.WriteLine("Greeting: " + reply.ResponseMsg);


            var response = client.SayGoodbye(new GoodByeRequest()
            {
                Name = user
            });

            Console.WriteLine("Response: " + response.ResponseMsg);

            await channel.ShutdownAsync();

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            var host = "127.0.0.1";
            var port = "8888";


            var channel = new Channel($"{host}:{port}", ChannelCredentials.Insecure);

            var serviceClient = new gRPCService.gRPCServiceClient(channel);

            var result = serviceClient.AddUser(new AddUserRequest
            {
                Name = "Yowko",
                Age  = 35
            });

            var addResult = JsonConvert.DeserializeObject <UserModel>(result.ResultMsg);

            Console.WriteLine($"Id:{addResult.Id};Name:{addResult.Name};Age:{addResult.Age}");

            var usersResult = serviceClient.GetUsers(new GetUsersRequest());

            var users = usersResult.ResultMsgs.Select(a => JsonConvert.DeserializeObject <UserModel>(a));


            foreach (var user in users)
            {
                Console.WriteLine($"Id:{user.Id};Name:{user.Name};Age:{user.Age}");
            }


            var deleteResult = serviceClient.DeleteUser(new DeleteUserRequest()
            {
                Name = "Yowko"
            });

            var delResult = deleteResult.ResultMsg;

            Console.WriteLine($"Msg:{delResult}");
        }