public ThriftDemoService()
        {
            this.Transport = new TSocket(this.Host, this.Port);
            if (this.ProtocolType == "compact")
            {
                this.Protocol = new TCompactProtocol(this.Transport);
            }
            else if (this.ProtocolType == "json")
            {
                Protocol = new TJSONProtocol(this.Transport);
            }
            else
            {
                Protocol = new TBinaryProtocol(this.Transport);
            }
            this.Client = new RPCDemoService.Client(this.Protocol);

            if (!this.Transport.IsOpen)
            {
                this.Transport.Open();
            }
        }
示例#2
0
        public static void ClientTest(string host, int port, string certPath, string url, string pipe, bool encrypted, bool buffered, bool framed)
        {
            TTransport trans = null;

            if (url == null)
            {
                // endpoint transport

                if (pipe != null)
                {
                    trans = new TNamedPipeClientTransport(pipe);
                }
                else
                {
                    if (encrypted)
                    {
                        trans = new TTLSSocket(host, port, certPath);
                    }
                    else
                    {
                        trans = new TSocket(host, port);
                    }
                }

                // layered transport
                if (buffered)
                {
                    trans = new TBufferedTransport(trans as TStreamTransport);
                }
                if (framed)
                {
                    trans = new TFramedTransport(trans);
                }

                //ensure proper open/close of transport
                trans.Open();
            }
            else
            {
                trans = new THttpClient(new Uri(url));
            }


            TProtocol proto;

            if (protocol == "compact")
            {
                proto = new TCompactProtocol(trans);
            }
            else if (protocol == "json")
            {
                proto = new TJSONProtocol(trans);
            }
            else
            {
                proto = new TBinaryProtocol(trans);
            }

            RPCDemoService.Client client = new RPCDemoService.Client(proto);
            try
            {
                if (!trans.IsOpen)
                {
                    trans.Open();
                }
            }
            catch (TTransportException ttx)
            {
                Console.WriteLine("Connect failed: " + ttx.Message);
                return;
            }

            var stopwatch = Stopwatch.StartNew();

            for (var i = 0; i < length; i++)
            {
                var reply = client.GetById(i);
                Console.WriteLine("receive" + JsonConvert.SerializeObject(reply));
            }
            stopwatch.Stop();

            Console.WriteLine(string.Format("repeat={0}, time={1} Milliseconds, time/repeat={2}", length, stopwatch.ElapsedMilliseconds, stopwatch.ElapsedMilliseconds / (float)length));
            Console.ReadKey();
        }
示例#3
0
        public static void ClientTest(string host, int port, string certPath, string url, string pipe, bool encrypted, bool buffered, bool framed, string protocol, int i)
        {
            TTransport trans = null;

            if (url == null)
            {
                if (pipe != null)
                {
                    trans = new TNamedPipeClientTransport(pipe);
                }
                else
                {
                    if (encrypted)
                    {
                        trans = new TTLSSocket(host, port, certPath);
                    }
                    else
                    {
                        trans = new TSocket(host, port);
                    }
                }

                // layered transport
                if (buffered)
                {
                    trans = new TBufferedTransport(trans as TStreamTransport);
                }
                if (framed)
                {
                    trans = new TFramedTransport(trans);
                }

                //ensure proper open/close of transport
                trans.Open();
            }
            else
            {
                trans = new THttpClient(new Uri(url));
            }

            TProtocol proto;

            if (protocol == "compact")
            {
                proto = new TCompactProtocol(trans);
            }
            else if (protocol == "json")
            {
                proto = new TJSONProtocol(trans);
            }
            else
            {
                proto = new TBinaryProtocol(trans);
            }

            RPCDemoService.Client client = new RPCDemoService.Client(proto);
            try
            {
                if (!trans.IsOpen)
                {
                    trans.Open();
                }
            }
            catch (TTransportException ttx)
            {
                Console.WriteLine("Connect failed: " + ttx.Message);
                return;
            }

            var reply = client.GetById(i);

            Console.WriteLine("receive" + JsonConvert.SerializeObject(reply));
            trans.Close();
        }