Beispiel #1
0
        static void RunOrleans()
        {
            var config = ClientConfiguration.LocalhostSilo(26224);

            try
            {
                GrainClient.Initialize(config);
                Console.WriteLine("Client successfully connect to silo host");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Orleans client initialization failed failed due to {ex}");

                Console.ReadLine();
                return;
            }

            var friend = GrainClient.GrainFactory.GetGrain <IHello>(0);
            var name   = "world";

            CodeTimerAdvance.TimeByConsole("orleans", _count, (i) =>
            {
                var response = friend.SayHello(new RpcTest_OrleansServer.Interfaces.HelloRequest
                {
                    Name = name
                }).Result;
            }, _threadcount);

            Console.WriteLine("Press Enter to terminate...");
            Console.ReadLine();
        }
Beispiel #2
0
        static void RunThriftBio()
        {
            //TTransport transport = new TSocket("localhost", 7911);
            //TProtocol protocol = new TBinaryProtocol(transport);
            //Helloword.Client client = new Helloword.Client(protocol);
            //transport.Open();
            //String user = "******";
            //CodeTimerAdvance.TimeByConsole("thrift bio", _count, a =>
            //{
            //    var reply = client.SayHello(new HelloRequest { Name = user });
            //}, _threadcount);
            //transport.Close();


            //多线程不能复用TSocket故需每次实例化。
            String user = "******";

            CodeTimerAdvance.TimeByConsole("thrift bio", _count, a =>
            {
                TTransport transport = new TSocket("localhost", 7911);
                transport.Open();
                TProtocol protocol = new TBinaryProtocol(transport);
                using (Helloword.Client client = new Helloword.Client(protocol))
                {
                    var reply = client.SayHello(new HelloRequest {
                        Name = user
                    });
                }
                transport.Close();
            }, _threadcount);
        }
Beispiel #3
0
        static void RunHttpClient()
        {
            var httpClient = new HttpClient();

            CodeTimerAdvance.TimeByConsole("httpclient", _count, a =>
            {
                var response = httpClient.PostAsync("http://localhost:23455/api/Values/SayHello", new FormUrlEncodedContent(new Dictionary <string, string>
                {
                    { "Name", "world" },
                }));
                var res = response.Result.Content.ReadAsStringAsync().Result;
            }, _threadcount);
        }
Beispiel #4
0
        static void RunGrpc()
        {
            Channel channel = new Channel("127.0.0.1:50051", ChannelCredentials.Insecure);
            String  user    = "******";

            CodeTimerAdvance.TimeByConsole("gRpc", _count, a =>
            {
                var client = new Greeter.GreeterClient(channel);
                var reply  = client.SayHello(new Helloworld.HelloRequest {
                    Name = user + a
                });
            }, _threadcount);
            channel.ShutdownAsync().Wait();
        }
Beispiel #5
0
        static void RunWcfTcp()
        {
            string address = "net.tcp://localhost:8002/";
            ChannelFactory <RpcTest_WCFServer.IHelloword> channel =
                new ChannelFactory <RpcTest_WCFServer.IHelloword>(
                    new NetTcpBinding(),
                    new EndpointAddress(
                        new Uri(address)));

            RpcTest_WCFServer.IHelloword proxy = channel.CreateChannel();
            String user = "******";

            CodeTimerAdvance.TimeByConsole("wcf tcp", _count, a =>
            {
                var reply = proxy.SayHello(new RpcTest_WCFServer.HelloRequest {
                    Name = user
                }).Result;
            }, _threadcount);
        }
Beispiel #6
0
        static void RunHttpWebRequest()
        {
            string url = "http://localhost:23455/api/Values/SayHello";

            CodeTimerAdvance.TimeByConsole("HttpWebRequest", _count, a =>
            {
                HttpWebRequest webRequest  = (HttpWebRequest)WebRequest.Create(new Uri(url));
                webRequest.Method          = "post";
                webRequest.ContentType     = "application/x-www-form-urlencoded";
                string postData            = "Name=world";
                byte[] byteArray           = Encoding.UTF8.GetBytes(postData);
                webRequest.ContentLength   = byteArray.Length;
                System.IO.Stream newStream = webRequest.GetRequestStream();
                newStream.Write(byteArray, 0, byteArray.Length);
                newStream.Close();
                HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
                string res = new System.IO.StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8")).ReadToEnd();
            }, _threadcount);
        }