Пример #1
0
        public async static Task RunClient()
        {
            var proxy = new ClientProxyBuilder().UseServer("127.0.0.1:6201").BuildDefault();

            using (var client = proxy.GetClient <MathCommon.MathClient>())
            {
                Console.WriteLine("ready to send message");

                var random = new Random();

                AddReq req = new AddReq
                {
                    A = random.Next(1, 10000),
                    B = random.Next(1, 10000)
                };

                Console.WriteLine("call sever MathService.Add  --> {0}+{1} ", req.A, req.B);

                try
                {
                    var res = await client.AddAsync(req);

                    Console.WriteLine("server repsonse:<-----{0}+{1}={2}", req.A, req.B, res.Data.C);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("error occ {0}", ex.Message);
                }
            }
            Console.WriteLine("channel is closed!");
        }
Пример #2
0
        public async static Task RunClient()
        {
            var proxy = new ClientProxyBuilder().UseServer("127.0.0.1:6201")
                        .ConfigureServices(services =>
            {
                services.AddSingleton <IProtobufObjectFactory, ProtobufObjectFactory>();

                services.AddSingleton <IAuditLoggerFormat <AmpMessage>, AuditLoggerFormat>();
            })
                        .ConfigureLoggingServices(logger => logger.AddSerilog(dispose: true))
                        .BuildDefault();



            using (var client = proxy.GetClient <MathCommon.MathClient>())
            {
                Console.WriteLine("ready to send message");

                var random = new Random();
                var i      = 0;
                while (i < 10)
                {
                    AddReq req = new AddReq
                    {
                        A = random.Next(1, 10000),
                        B = random.Next(1, 10000)
                    };

                    Console.WriteLine("call sever MathService.Add  --> {0}+{1} ", req.A, req.B);

                    try
                    {
                        var res = await client.AddAsync(req);

                        Console.WriteLine("server repsonse:<-----{0}+{1}={2}", req.A, req.B, res.Data?.C);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("error occ {0}", ex.Message);
                    }

                    i++;
                }
            }
            Console.WriteLine("Press any key to quit!");
            Console.ReadKey();
        }