예제 #1
0
        static void Main(string[] args)
        {
            using (TTransport transport = new TSocket("localhost", 9081))
                using (TProtocol protocol = new TBinaryProtocol(transport))

                    using (var protocolHelloService = new TMultiplexedProtocol(protocol, "helloService"))
                        using (var clientHello = new HelloService.Client(protocolHelloService))
                            using (var protocolSchoolService = new TMultiplexedProtocol(protocol, "schoolService"))
                                using (var clientSchool = new SchoolService.Client(protocolSchoolService))
                                {
                                    transport.Open();

                                    Console.WriteLine(clientHello.HelloString("hello world"));
                                    Console.WriteLine("===========================");
                                    //调用服务端的方法
                                    var result = clientSchool.GetAllBanji();
                                    Console.WriteLine(result.SchoolName);
                                    foreach (var item in result.AllBanji)
                                    {
                                        Console.WriteLine("--" + item.BanjiName);
                                        foreach (var student in item.AllStudents)
                                        {
                                            Console.WriteLine("----" + student.StudentName);
                                        }
                                    }
                                }

            Console.ReadKey();
        }
예제 #2
0
        static void Main(string[] args)
        {
            Uri         uri        = new Uri("http://localhost:8911/");
            THttpClient httpClient = new THttpClient(uri);
            TProtocol   protocol   = new TBinaryProtocol(httpClient);

            HelloService.Client client = new HelloService.Client(protocol);
            httpClient.Open();
            Console.WriteLine("Client calls .....");
            Console.WriteLine(client.hello("jian wang"));
            Console.WriteLine(client.add(1, 2));
            httpClient.Close();
            Console.ReadKey();
        }
예제 #3
0
        public void TestMethod1()
        {
            try
            {
                // 设置服务端端口号和地址
                TTransport transport = new TSocket("localhost", 7911);

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

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

                // 调用服务端的方法
                Console.WriteLine(client.HelloString("HelloThrift"));
                Console.WriteLine(client.HelloInt(11));
                Console.WriteLine(client.HelloBoolean(false));

                transport.Close();

                Console.ReadKey();
            }
            catch (TTransportException e)
            {
                Console.WriteLine(e.Message);
            }
        }
예제 #4
0
 static void Main(string[] args)
 {
     try
     {
         //设置服务端端口号和地址
         TTransport transport = new TSocket("localhost", 8085);
         transport.Open();
         //设置传输协议为二进制传输协议
         TProtocol protocol = new TBinaryProtocol(transport);
         //创建客户端对象
         HelloService.Client client = new HelloService.Client(protocol);
         //调用服务端的方法
         Console.WriteLine(client.HelloInt(123));
         Console.ReadKey();
     }
     catch (TTransportException e)
     {
         Console.WriteLine(e.Message);
     }
 }