예제 #1
0
        static void Main(string[] args)
        {
            var proxy = ClientProxyFactory.Create()
                        .UseCastleDynamicClientProxy()
                        .UseJsonNetSerializer()
                        .UseDefaultChannel($"{IPUtility.GetLocalIntranetIP().MapToIPv4()}:5566")
                        .GetClientProxy();


            var mathService = proxy.Create <IMathService>();


            var random = new Random();

            var req = new SumReq {
                A = random.Next(100000), B = random.Next(100000)
            };
            var result = mathService.SumAsync(req).GetAwaiter().GetResult();

            if (result.Code == 0)
            {
                Console.WriteLine("Call Math Service Add {0}+{1}={2}", req.A, req.B, result.Data?.Total);
            }
            else
            {
                Console.WriteLine("Call Math Service Error,Code={0}", result.Code);
            }

            Console.WriteLine("Press any key to exit !");
            Console.ReadKey();
        }
예제 #2
0
파일: Program.cs 프로젝트: dl1109783/dotbpe
        static void Main(string[] args)
        {
            /* default route  */
            var factory = ClientProxyFactory.Create()
                          .UseCastleDynamicClientProxy()
                          .ConfigureLogging(logger => logger.AddConsole())
                          .UseMessagePackSerializer()
                          .UseDefaultChannel($"{IPUtility.GetLocalIntranetIP().MapToIPv4()}:5566");



            /* service discovery route
             * var factory = ClientProxyFactory.Create()
             *  .ConfigureLogging(logger =>logger.AddConsole())
             *  .UseCastleDynamicProxy()
             *  .UseMessagePackSerializer()
             *  .UseConsulDnsServiceDiscovery(); //默认配置 localhost
             */

            var proxy = factory.GetProxyInstance();

            var mathService = proxy.Create <IMathService>();

            var i      = 0;
            var random = new Random();

            while (i++ < 100)
            {
                var req = new SumReq {
                    A = random.Next(100000), B = random.Next(100000)
                };
                var result = mathService.SumAsync(req).Result;

                Console.WriteLine("Call Math Service ,return_code={0}", result.Code);
                if (result.Code == 0)
                {
                    Console.WriteLine("Call Math Service Add {0}+{1}={2}", req.A, req.B, result.Data?.Total);
                }

                Console.WriteLine("============= count:{0}", i);
            }

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