Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            localhost.ServiceClient proxy = new localhost.ServiceClient();
            try
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("Calling proxy.ThrowException()");
                Console.WriteLine("");
                Console.ResetColor();

                proxy.ThrowException();

                System.Console.WriteLine("SUCCESS: proxy.ThrowException");
            }
            catch (CommunicationException communicationException)
            {
                Console.WriteLine(communicationException.GetType().ToString());
                Console.WriteLine("ERROR: {0}", communicationException.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.GetType().ToString());
                Console.WriteLine("ERROR: {0}", ex.Message);
            }

            Console.WriteLine();

            try
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("Calling proxy.ThrowExceptionOneWay()");
                Console.ResetColor();

                proxy.ThrowExceptionOneWay();
                System.Console.WriteLine("SUCCESS: proxy.ThrowExceptionOneWay");
            }
            catch (CommunicationException communicationException)
            {
                Console.WriteLine(communicationException.GetType().ToString());
                Console.WriteLine("ERROR: {0}", communicationException.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.GetType().ToString());
                Console.WriteLine("ERROR:  {0}", ex.Message);
            }

            proxy.Close();

            Console.WriteLine();
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine("Press <ENTER> to terminate Client.");
            Console.ReadLine();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            localhost.ServiceClient proxy = new localhost.ServiceClient();

            try
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("Calling proxy.ThrowException()");
                Console.WriteLine("");
                Console.ResetColor();

                proxy.ThrowException();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.GetType().ToString());
                Console.WriteLine("ERROR: {0}", ex.Message);
            }

            Console.WriteLine();
            Console.WriteLine("Proxy state after exception: {0}", proxy.State);
            Console.WriteLine();

            if (proxy.State == CommunicationState.Faulted)
            {
                proxy = new localhost.ServiceClient();
            }

            try
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("Calling proxy.ThrowExceptionOneWay()");
                Console.ResetColor();

                proxy.ThrowExceptionOneWay();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.GetType().ToString());
                Console.WriteLine("ERROR:  {0}", ex.Message);
            }


            Console.WriteLine();
            Console.WriteLine("Proxy state after exception: {0}", proxy.State);
            Console.WriteLine();


            try
            {
                proxy.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.GetType().ToString());
                Console.WriteLine("ERROR:  {0}", ex.Message);
            }

            Console.WriteLine();
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine("Press <ENTER> to terminate Client.");
            Console.ReadLine();
        }