Example #1
0
        static void Main(string[] args)
        {
            //for (int i = 0; i < 3; i++)
            //{
            //    Console.WriteLine("{0}: Calling GetPrice", System.DateTime.Now);
            //    proxy.BeginGetPrice("MSFT", GetPriceCallBack, proxy);
            //    Thread.Sleep(500);
            //    Interlocked.Increment(ref c);
            //}

            //TaskScheduler scheduler = TaskScheduler.FromCurrentSynchronizationContext();
            StockServiceClient proxy = new StockServiceClient("WSHttpBinding_IStockService");

            while (Console.ReadLine() == "")
            {
                var task = Task.Factory.StartNew(() =>
                {
                    //Invoke Service

                    Console.WriteLine("{0}: Calling GetPrice", System.DateTime.Now);
                    StockPrice res = proxy.GetPrice("test");

                    return(res);
                }).ContinueWith(i =>
                {
                    if (i.Exception != null)
                    {
                        //this.Dispatcher.BeginInvoke(new Action(() =>
                        // {

                        // }),null);
                    }
                    else
                    {
                        // this.Dispatcher.BeginInvoke(new Action(() =>
                        // {
                        Console.WriteLine("Result in : {0}, Price:{1},calls : {2}", System.DateTime.Now, i.Result.price, i.Result.calls);
                        Console.ReadLine();
                        // }),null);
                    }
                } /*scheduler*/);
            }
            Console.ReadLine();

            //while (true)
            //{
            //    Console.WriteLine("{0}: Calling GetPrice", System.DateTime.Now);
            //    StockPrice res = proxy.GetPrice("test");
            //    //proxy.BeginGetPrice("MSFT", GetPriceCallBack, proxy);
            //    Console.WriteLine("Result in : {0}, Price:{1},calls : {2}", System.DateTime.Now,res.price,res.calls);
            //    Console.ReadLine();
            //}

            //Console.ReadLine();
        }
Example #2
0
        static void Main()
        {
            StockServiceClient proxy = new StockServiceClient();

            double p = proxy.GetPrice("msft");

            Console.WriteLine("Price:{0}", p);
            Console.ReadKey();

            proxy.Close();
        }
Example #3
0
        static void Main(string[] args)
        {
            StockServiceClient proxy = new StockServiceClient("WSHttpBinding_IStockService");

            while (true)
            {
                Console.WriteLine("{0}: Calling GetPrice", System.DateTime.Now);
                StockPrice res = proxy.GetPrice("test");
                Console.WriteLine("Result in : {0}, Price:{1},calls : {2},\n requested by {3}", System.DateTime.Now, res.price, res.calls, res.RequestedBy);
                Console.ReadLine();
            }
        }
Example #4
0
        static void Main(string[] args)
        {
            StockServiceClient service = new StockServiceClient();

            Console.WriteLine(service.GetMessage());
            Console.WriteLine("Enter name:");
            var name = Console.ReadLine();
            while (name != "quit")
            {
                try
                {
                    double price=service.GetPrice(name, 0);
                    Console.WriteLine(string.Format("Price: {0}", price));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                Console.WriteLine("Enter name:");
                name = Console.ReadLine();
            }
        }