public void CloseSession()
 {
     try
     {
         if (client != null)
         {
             if (client.State == System.ServiceModel.CommunicationState.Opened)
             {
                 client.Close();
             }
             else if (client.State == System.ServiceModel.CommunicationState.Faulted)
             {
                 client.Abort();
             }
         }
     }
     catch (FaultException)
     {
         client.Abort();
     }
     catch (CommunicationException)
     {
         client.Abort();
     }
     catch (TimeoutException)
     {
         client.Abort();
     }
     catch { throw; }
 }
        public static void Wait()
        {
            PermissiveCertificatePolicy.Enact("CN=HTTPS-Server");

            bool productServiceIsRunning = false;

            Console.Write("Waiting for Product Service... ");
            while (!productServiceIsRunning)
            {
                System.Threading.Thread.Sleep(500);

                try
                {
                    BicycleWorldServiceClient proxy = new BicycleWorldServiceClient("DefaultBinding_BicycleWorldService_BicycleWorldService");
                    proxy.ClientCredentials.UserName.UserName = "******";
                    proxy.ClientCredentials.UserName.Password = "******";
                    proxy.Login();
                    productServiceIsRunning = true;
                    proxy.Abort();

                    Console.WriteLine("Connected.");
                }
                catch (ServerTooBusyException)
                {
                    Console.Write(".");
                }
                catch (SecurityAccessDeniedException ex)
                {
                    Console.WriteLine("\n {0}", ex.Message);
                    break;
                }
                catch (Exception ex)
                {
                    Console.Write(ex.Message);
                }
            }

            bool salesServiceIsRunning = false;

            Console.Write("Waiting for Sales Service... ");
            while (!salesServiceIsRunning)
            {
                System.Threading.Thread.Sleep(500);

                try
                {
                    BicycleWorldSalesServiceClient proxy = new BicycleWorldSalesServiceClient("wsHttpBinding_BicycleWorldSalesService");
                    proxy.ClientCredentials.UserName.UserName = "******";
                    proxy.ClientCredentials.UserName.Password = "******";
                    proxy.Login();
                    salesServiceIsRunning = true;
                    proxy.Abort();

                    Console.WriteLine("Connected.");
                }
                catch (ServerTooBusyException)
                {
                    Console.Write(".");
                }
                catch (Exception ex)
                {
                    Console.Write(ex.Message);
                }
            }
        }
Ejemplo n.º 3
0
        public static void Wait()
        {
            PermissiveCertificatePolicy.Enact("CN=HTTPS-Server");

            bool productServiceIsRunning = false;

            Console.Write("Waiting for Product Service... ");
            while (!productServiceIsRunning)
            {
                System.Threading.Thread.Sleep(500);

                try
                {
                    BicycleWorldServiceClient proxy = new BicycleWorldServiceClient("DefaultBinding_BicycleWorldService_BicycleWorldService");
                    proxy.ClientCredentials.UserName.UserName = "******";
                    proxy.ClientCredentials.UserName.Password = "******";
                    proxy.Login();
                    productServiceIsRunning = true;
                    proxy.Abort();

                    Console.WriteLine("Connected.");
                }
                catch (ServerTooBusyException)
                {
                    Console.Write(".");
                }
                catch (SecurityAccessDeniedException ex)
                {
                    Console.WriteLine("\n {0}", ex.Message);
                    break;
                }
                catch (Exception ex)
                {
                    Console.Write(ex.Message);
                }
            }

            bool salesServiceIsRunning = false;

            Console.Write("Waiting for Sales Service... ");
            while (!salesServiceIsRunning)
            {
                System.Threading.Thread.Sleep(500);

                try
                {
                    BicycleWorldSalesServiceClient proxy = new BicycleWorldSalesServiceClient("wsHttpBinding_BicycleWorldSalesService");
                    proxy.ClientCredentials.UserName.UserName = "******";
                    proxy.ClientCredentials.UserName.Password = "******";
                    proxy.Login();
                    salesServiceIsRunning = true;
                    proxy.Abort();

                    Console.WriteLine("Connected.");
                }
                catch (ServerTooBusyException)
                {
                    Console.Write(".");
                }
                catch (Exception ex)
                {
                    Console.Write(ex.Message);
                }
            }
        }