Пример #1
0
        static void Main(string[] args)
        {
            try
            {
                ChannelFactory <IWCFFizzBuzzService> channelFactory = new
                                                                      ChannelFactory <IWCFFizzBuzzService>("FizzBuzzServiceEndpoint");

                IWCFFizzBuzzService proxy = channelFactory.CreateChannel();

                Console.Write("Enter random number: ");
                string input = Console.ReadLine();
                if (input != null &&
                    input != String.Empty &&
                    Int32.TryParse(input, out int num))
                {
                    // Llama al servidor a través de la proxy
                    List <string> sequence = proxy.GetData(input);
                    foreach (var s in sequence)
                    {
                        centerText(s);
                    }
                }
                else if (input != String.Empty)
                {
                    throw new NotAnIntegerException();
                }
                else
                {
                    throw new EmptyValueException();
                }

                Console.ReadLine();
            }
            catch (EmptyValueException ev)
            {
                Console.WriteLine(ev.Message);
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                Console.WriteLine("\r\n");
                string text = "<Press enter to close window>";
                Console.SetCursorPosition((Console.WindowWidth - text.Length) / 2, Console.CursorTop);
                Console.WriteLine(text);
                Console.ReadLine();
            }
        }
Пример #2
0
        private static List <string> getDataLists()
        {
            List <string> strList = null;
            ChannelFactory <IWCFFizzBuzzService> channelFactory = null;

            try
            {
                channelFactory = new ChannelFactory <IWCFFizzBuzzService>("FizzBuzzServiceEndpoint");
                IWCFFizzBuzzService proxy = channelFactory.CreateChannel();
                strList = proxy.GetData("0");
                channelFactory.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                channelFactory.Abort();
            }

            return(strList);
        }