static void WcfTest()
        {
            int threadCount = 4;
            int port        = 9999;
            int count       = 10000;
            int errorCount  = 0;

            WcfHost <IHello, Hello> wcfHost = new WcfHost <IHello, Hello>();

            wcfHost.StartHost();
            IHello client = WcfClient.GetService <IHello>("http://127.0.0.1:14725");

            client.SayHello("Hello");
            Stopwatch   watch = new Stopwatch();
            List <Task> tasks = new List <Task>();

            watch.Start();
            LoopHelper.Loop(threadCount, () =>
            {
                tasks.Add(Task.Run(() =>
                {
                    LoopHelper.Loop(count, index =>
                    {
                        var msg = client.SayHello("Hello" + index);
                        //Console.WriteLine($"{DateTime.Now.ToString("HH:mm:ss:ffffff")}:{msg}");
                    });
                }));
            });
            Task.WaitAll(tasks.ToArray());
            watch.Stop();
            Console.WriteLine($"并发数:{threadCount},运行:{count}次,每次耗时:{(double)watch.ElapsedMilliseconds / count}ms");
        }
Beispiel #2
0
        static void WcfTest()
        {
            int count = int.MaxValue;

            WcfHost <IHello, Hello> wcfHost = new WcfHost <IHello, Hello>();

            wcfHost.StartHost();
            IHello client = WcfClient.GetService <IHello>("http://127.0.0.1:14725");

            client.SayHello("Hello");
            Stopwatch watch = new Stopwatch();

            watch.Start();
            LoopHelper.Loop(1, () =>
            {
                Task.Run(() =>
                {
                    LoopHelper.Loop(count, index =>
                    {
                        var msg = client.SayHello("Hello" + index);
                        Console.WriteLine($"{DateTime.Now.ToString("HH:mm:ss:ffffff")}:{msg}");
                    });
                }).Wait();
            });
            watch.Stop();
            Console.WriteLine($"每次耗时:{(double)watch.ElapsedMilliseconds / count}ms");
        }