Example #1
0
        private static void Main(string[] args)
        {
            //using (TTransport transport = new TSocket("127.0.0.1", 8888))
            //using (TProtocol protocol = new TBinaryProtocol(transport))
            //using (var clientUser = new UserService.Client(protocol))
            //{
            //    transport.Open();
            //    User u = clientUser.Get(1);
            //    Console.WriteLine($"{u.Id},{u.Name}");
            //}

            using (TTransport transport = new TSocket("127.0.0.1", 8888))
                using (TProtocol protocol = new TBinaryProtocol(transport))
                    using (var protocolUserService = new TMultiplexedProtocol(protocol, "userService"))
                        using (var clientUser = new UserService.Client(protocolUserService))
                            using (var protocolCalcService = new TMultiplexedProtocol(protocol, "calcService"))
                                using (var clientCalc = new CalcService.Client(protocolCalcService))
                                {
                                    transport.Open();
                                    User u = clientUser.Get(1);
                                    Console.WriteLine($"{u.Id},{u.Name}");
                                    Console.WriteLine(clientCalc.Add(1, 2));
                                }

            Console.ReadKey();
        }
Example #2
0
        static void Main(string[] args)
        {
            using (TTransport transport = new TSocket("localhost", 8800))
                using (TProtocol protocol = new TBinaryProtocol(transport))
                    using (var clientUser = new UserService.Client(protocol))
                    {
                        transport.Open();
                        var users = clientUser.GetAll();
                        foreach (var u in users)
                        {
                            Console.WriteLine($"{u.Id},{u.Name}");
                        }
                    }

            /*
             * using (TTransport transport = new TSocket("localhost", 8800))
             * using (TProtocol protocol = new TBinaryProtocol(transport))
             * using (var protocolUserService = new TMultiplexedProtocol(protocol, "userService"))
             * using (var clientUser = new UserService.Client(protocolUserService))
             * using (var protocolCalcService = new TMultiplexedProtocol(protocol, "calcService"))
             * using (var clientCalc = new CalcService.Client(protocolCalcService))
             * {
             *  transport.Open();
             *  User u = clientUser.Get(1);
             *  Console.WriteLine($"{u.Id},{u.Name}");
             *  Console.WriteLine(clientCalc.Add(1, 2));
             * }*/


            Console.ReadKey();
        }
        public void TestMethod2()
        {
            try
            {
                // 设置服务端端口号和地址
                TTransport transport = new TSocket("localhost", 7911);

                /*
                 * 设置传输协议为二进制传输协议;
                 *
                 * Thrift可以让用户选择客户端与服务端之间传输通信协议的类别,
                 * 在传输协议上总体划分为文本(text)和二进制(binary)传输协议,
                 * 为节约带宽,提高传输效率,
                 * 一般情况下使用二进制类型的传输协议为多数,
                 * 有时还会使用基于文本类型的协议,
                 * 这需要根据项目/产品中的实际需求。
                 *
                 * 常用协议有以下几种:
                 * BinaryProtocol——二进制编码格式进行数据传输使,
                 * TCompactProtocol——高效率的、密集的二进制编码格式进行数据传输,
                 * TJSONProtocol——使用JSON 的数据编码协议进行数据传输。
                 *
                 */
                TProtocol protocol = new TBinaryProtocol(transport);
                // 创建客户端对象
                UserService.Client client = new UserService.Client(protocol);
                transport.Open();
                Console.WriteLine("Client calls .....");

                if (transport.IsOpen)
                {
                    // I am seeing this message
                    Console.WriteLine("server is open for business");
                }

                // 调用服务端的方法
                var result1 = client.GetAllUser();

                foreach (var user in result1)
                {
                    Console.WriteLine($"{user.Id},{user.UserName},{user.UserPass}");
                }


                transport.Close();

                Console.ReadKey();
            }
            catch (TTransportException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Example #4
0
 public Services(TTransport transport)
 {
     SessionService      = new SessionService.Client(new TMultiplexedProtocol(new TBinaryProtocol(new TFramedTransport(transport)), Utility.Helper.NameOf(() => SessionService)));
     UserService         = new UserService.Client(new TMultiplexedProtocol(new TBinaryProtocol(new TFramedTransport(transport)), Utility.Helper.NameOf(() => UserService)));
     SettingService      = new SettingService.Client(new TMultiplexedProtocol(new TBinaryProtocol(new TFramedTransport(transport)), Utility.Helper.NameOf(() => SettingService)));
     ChatService         = new ChatService.Client(new TMultiplexedProtocol(new TBinaryProtocol(new TFramedTransport(transport)), Utility.Helper.NameOf(() => ChatService)));
     ChatUserInfoService = new ChatUserInfoService.Client(new TMultiplexedProtocol(new TBinaryProtocol(new TFramedTransport(transport)), Utility.Helper.NameOf(() => ChatUserInfoService)));
     ChatGroupService    = new ChatGroupService.Client(new TMultiplexedProtocol(new TBinaryProtocol(new TFramedTransport(transport)), Utility.Helper.NameOf(() => ChatGroupService)));
     InboxService        = new InboxService.Client(new TMultiplexedProtocol(new TBinaryProtocol(new TFramedTransport(transport)), Utility.Helper.NameOf(() => InboxService)));
     InboxRuleService    = new InboxRuleService.Client(new TMultiplexedProtocol(new TBinaryProtocol(new TFramedTransport(transport)), Utility.Helper.NameOf(() => InboxRuleService)));
     ElifService         = new ElifService.Client(new TMultiplexedProtocol(new TBinaryProtocol(new TFramedTransport(transport)), Utility.Helper.NameOf(() => ElifService)));
     SearchService       = new SearchService.Client(new TMultiplexedProtocol(new TBinaryProtocol(new TFramedTransport(transport)), Utility.Helper.NameOf(() => SearchService)));
     NotificationService = new NotificationService.Client(new TMultiplexedProtocol(new TBinaryProtocol(new TFramedTransport(transport)), Utility.Helper.NameOf(() => NotificationService)));
 }
Example #5
0
 private static void SingleService1()
 {
     using (TTransport transport = new TSocket("localhost", 8800))
     {
         using (TProtocol protocol = new TBinaryProtocol(transport))
         {
             using (var clientUser = new UserService.Client(protocol))
             {
                 transport.Open();
                 User u = clientUser.Get(1); Console.WriteLine($"{u.Id},{u.Name}");
             }
         }
     }
 }
Example #6
0
 private static void Main(string[] args)
 {
     using (TTransport transport = new TSocket("localhost", 8800))
         using (TProtocol protocol = new TBinaryProtocol(transport))
             using (var protocolUserService = new TMultiplexedProtocol(protocol, "UserService"))
                 using (var clientUser = new UserService.Client(protocolUserService))
                     using (var protocolCalcService = new TMultiplexedProtocol(protocol, "CalcService"))
                         using (var clientCalc = new CalcService.Client(protocolCalcService))
                         {
                             transport.Open();
                             User u = clientUser.Get(1);
                             Console.WriteLine($"{u.Id},{u.Name}");
                             Console.WriteLine(clientCalc.Add(1, 2));
                         }
 }
Example #7
0
 static void Main(string[] args)
 {
     using (TTransport transport = new TSocket("localhost", 8800))
         using (TProtocol protocol = new TBinaryProtocol(transport))
             using (var clientUser = new UserService.Client(protocol))
             {
                 transport.Open();
                 User u = clientUser.Get(1);
                 Console.WriteLine($"{u.Id},{u.Name}");
                 var list = clientUser.GetAll();
                 list.ForEach(e =>
                 {
                     Console.WriteLine($"{e.Id},{e.Name}");
                 });
             }
 }
Example #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            Console.Title = "Thrift客户端-Client";
            TTransport transport = new TSocket("10.10.10.19", 10501);
            TProtocol  protocol  = new TBinaryProtocol(transport);

            UserService.Client client = new UserService.Client(protocol);
            transport.Open();
            //var users = client.GetAllUser();

            //users.ForEach(u => Console.WriteLine(string.Format("User ID : {0}, User Name {1}", u.ID, u.Name)));
            var user = client.GetUserByID(1);

            Console.WriteLine("------------------");
            Console.WriteLine(string.Format("User ID : {0}, User Name {1}", user.ID, user.Name));
            Console.ReadLine();
        }
Example #9
0
        static void Main(string[] args)
        {
            try

            {
                //设置服务端端口号和地址

                TTransport transport = new TSocket("localhost", 8800);

                transport.Open();

                //设置传输协议为二进制传输协议

                TProtocol protocol = new TBinaryProtocol(transport);

                //创建客户端对象

                UserService.Client client = new UserService.Client(protocol);



                //调用服务端的方法

                Console.WriteLine(client.GetUserName(11));

                Console.WriteLine(client.GetUserInfo(11));
                var c = client.GetUserInfo(11);
                Console.WriteLine(c.UserId);
                Console.WriteLine(c.UserName);
                Console.WriteLine(c.TrueName);
                Console.ReadKey();
            }

            catch (TTransportException e)
            {
                Console.WriteLine(e.Message);
            }
        }