private void Button_Click(object sender, RoutedEventArgs e) { LoginUser.Current.Reset(); string username = txtUsername.Text; string password = txtPassword.Password; PermissiveCertificatePolicy.Enact("CN=HTTPS-Server"); BicycleWorldSalesServiceClient proxy = new BicycleWorldSalesServiceClient("wsHttpBinding_BicycleWorldSalesService"); proxy.ClientCredentials.UserName.UserName = username; proxy.ClientCredentials.UserName.Password = password; try { proxy.Login(); bool isAdmin = proxy.IsUserAdmin(); LoginUser.Current.Set(username, password, isAdmin); DialogResult = true; Authenicated = true; this.Close(); } catch (MessageSecurityException ex) { MessageBox.Show((ex.InnerException != null) ? ex.InnerException.Message : "Login failed."); DialogResult = true; Authenicated = false; } catch (Exception) { MessageBox.Show("Login failed."); DialogResult = true; Authenicated = false; } }
private void Button_Click(object sender, RoutedEventArgs e) { LoginUser.Current.Reset(); string username = txtUsername.Text; string password = txtPassword.Password; PermissiveCertificatePolicy.Enact("CN=HTTPS-Server"); BicycleWorldSalesServiceClient proxy = new BicycleWorldSalesServiceClient("wsHttpBinding_BicycleWorldSalesService"); proxy.ClientCredentials.UserName.UserName = username; proxy.ClientCredentials.UserName.Password = password; try { proxy.Login(); bool isAdmin = proxy.IsUserAdmin(); LoginUser.Current.Set(username, password, isAdmin); DialogResult = true; Authenicated = true; this.Close(); } catch (MessageSecurityException ex) { MessageBox.Show((ex.InnerException != null) ? ex.InnerException.Message : "Login failed."); DialogResult = true; Authenicated = false; } catch (Exception) { MessageBox.Show("Login failed."); DialogResult = true; Authenicated = false; } }
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); } } }
public static void RunTest() { PermissiveCertificatePolicy.Enact("CN=HTTPS-Server"); Console.Write("Initializing Sales Proxy..."); BicycleWorldSalesServiceClient proxy = new BicycleWorldSalesServiceClient("wsHttpBinding_BicycleWorldSalesService"); Console.WriteLine(" done"); proxy.ClientCredentials.UserName.UserName = "******"; proxy.ClientCredentials.UserName.Password = "******"; // Test the operations in the service try { Console.WriteLine(proxy.Test()); // The encrypted list will timeout for slightly large lists (in the hundreds), so the list is // being grabbed in smaller chunks. Transaction logic is used to lock the list while the list is being // grabbed. TransactionOptions transactionOptions = new TransactionOptions(); transactionOptions.IsolationLevel = IsolationLevel.RepeatableRead; transactionOptions.Timeout = new TimeSpan(0, 2, 0); using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew, transactionOptions)) { Console.WriteLine("Test 1: List all Sales Orders"); int take = 5; int count = proxy.GetSalesOrderListCount(); for (int skip = 0; skip < count; skip = skip + take) { var salesOrders = proxy.GetSalesOrderList(take, skip); foreach (var saleOrder in salesOrders) { Console.WriteLine(" Sales Order ID: {0:000}", saleOrder.SalesOrderID); foreach (var item in saleOrder.SalesOrderItems) { Console.WriteLine(" Item Price: {0}, Item Quantity: {1}", item.ActualCost, item.Quantity); Console.WriteLine(" Name: {0}, Product Number: {1}", item.Product.Name, item.Product.ProductNumber); } } } //No scope.Complete here as no write tasks are being scoped. scope.Dispose(); } Console.WriteLine(); // Disconnect from the service proxy.Close(); } catch (FaultException<SystemFault> sf) { Console.WriteLine("SystemFault {0}: {1}\n{2}", sf.Detail.SystemOperation, sf.Detail.SystemMessage, sf.Detail.SystemReason); } catch (FaultException<DatabaseFault> dbf) { Console.WriteLine("DatabaseFault {0}: {1}\n{2}", dbf.Detail.DbOperation, dbf.Detail.DbMessage, dbf.Detail.DbReason); } catch (FaultException e) { Console.WriteLine("{0}: {1}", e.Code.Name, e.Reason); } catch (Exception e) { Console.WriteLine("General exception: {0}", e.Message); Console.WriteLine("Inner Exception: {0}", e.InnerException); } //Console.WriteLine("Press ENTER to continue"); //Console.ReadLine(); }
public static void RunTest() { PermissiveCertificatePolicy.Enact("CN=HTTPS-Server"); Console.Write("Initializing Sales Proxy..."); BicycleWorldSalesServiceClient proxy = new BicycleWorldSalesServiceClient("wsHttpBinding_BicycleWorldSalesService"); Console.WriteLine(" done"); proxy.ClientCredentials.UserName.UserName = "******"; proxy.ClientCredentials.UserName.Password = "******"; // Test the operations in the service try { Console.WriteLine(proxy.Test()); // The encrypted list will timeout for slightly large lists (in the hundreds), so the list is // being grabbed in smaller chunks. Transaction logic is used to lock the list while the list is being // grabbed. TransactionOptions transactionOptions = new TransactionOptions(); transactionOptions.IsolationLevel = IsolationLevel.RepeatableRead; transactionOptions.Timeout = new TimeSpan(0, 2, 0); using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew, transactionOptions)) { Console.WriteLine("Test 1: List all Sales Orders"); int take = 5; int count = proxy.GetSalesOrderListCount(); for (int skip = 0; skip < count; skip = skip + take) { var salesOrders = proxy.GetSalesOrderList(take, skip); foreach (var saleOrder in salesOrders) { Console.WriteLine(" Sales Order ID: {0:000}", saleOrder.SalesOrderID); foreach (var item in saleOrder.SalesOrderItems) { Console.WriteLine(" Item Price: {0}, Item Quantity: {1}", item.ActualCost, item.Quantity); Console.WriteLine(" Name: {0}, Product Number: {1}", item.Product.Name, item.Product.ProductNumber); } } } //No scope.Complete here as no write tasks are being scoped. scope.Dispose(); } Console.WriteLine(); // Disconnect from the service proxy.Close(); } catch (FaultException <SystemFault> sf) { Console.WriteLine("SystemFault {0}: {1}\n{2}", sf.Detail.SystemOperation, sf.Detail.SystemMessage, sf.Detail.SystemReason); } catch (FaultException <DatabaseFault> dbf) { Console.WriteLine("DatabaseFault {0}: {1}\n{2}", dbf.Detail.DbOperation, dbf.Detail.DbMessage, dbf.Detail.DbReason); } catch (FaultException e) { Console.WriteLine("{0}: {1}", e.Code.Name, e.Reason); } catch (Exception e) { Console.WriteLine("General exception: {0}", e.Message); Console.WriteLine("Inner Exception: {0}", e.InnerException); } //Console.WriteLine("Press ENTER to continue"); //Console.ReadLine(); }
public static void RunTestRemoveAndCheckoutItems() { PermissiveCertificatePolicy.Enact("CN=HTTPS-Server"); Console.Write("Initializing Sales Proxy..."); BicycleWorldSalesServiceClient proxy = new BicycleWorldSalesServiceClient("wsHttpBinding_BicycleWorldSalesService"); Console.WriteLine(" done"); proxy.ClientCredentials.UserName.UserName = "******"; proxy.ClientCredentials.UserName.Password = "******"; // Test the operations in the service try { Console.WriteLine("Press ENTER to start shopping cart"); Console.ReadLine(); TransactionOptions transactionOptions = new TransactionOptions(); transactionOptions.IsolationLevel = IsolationLevel.RepeatableRead; transactionOptions.Timeout = new TimeSpan(0, 1, 0); using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew, transactionOptions)) { IDictionary<string, string> context = null; IContextManager contextManager = proxy.InnerChannel.GetProperty<IContextManager>(); if (context != null) { contextManager.SetContext(context); } proxy.AddItemToCart("BK-M18B-42"); if (context == null) { context = contextManager.GetContext(); } Console.WriteLine(proxy.GetShoppingCart()); proxy.RemoveItemFromCart("BK-R19B-44"); Console.WriteLine(proxy.GetShoppingCart()); if (proxy.Checkout()) { scope.Complete(); Console.WriteLine("Goods purchased."); } } Console.WriteLine(); // Disconnect from the service proxy.Close(); } catch (FaultException<SystemFault> sf) { Console.WriteLine("SystemFault {0}: {1}\n{2}", sf.Detail.SystemOperation, sf.Detail.SystemMessage, sf.Detail.SystemReason); } catch (FaultException<DatabaseFault> dbf) { Console.WriteLine("DatabaseFault {0}: {1}\n{2}", dbf.Detail.DbOperation, dbf.Detail.DbMessage, dbf.Detail.DbReason); } catch (FaultException e) { Console.WriteLine("{0}: {1}", e.Code.Name, e.Reason); } catch (Exception e) { Console.WriteLine("General exception: {0}", e.Message); Console.WriteLine("Inner Exception: {0}", e.InnerException); } Console.WriteLine("Press ENTER to continue"); Console.ReadLine(); }
public static void RunTestRemoveAndCheckoutItems() { PermissiveCertificatePolicy.Enact("CN=HTTPS-Server"); Console.Write("Initializing Sales Proxy..."); BicycleWorldSalesServiceClient proxy = new BicycleWorldSalesServiceClient("wsHttpBinding_BicycleWorldSalesService"); Console.WriteLine(" done"); proxy.ClientCredentials.UserName.UserName = "******"; proxy.ClientCredentials.UserName.Password = "******"; // Test the operations in the service try { //Console.WriteLine(proxy.Login()); Console.WriteLine("Press ENTER to start shopping cart"); Console.ReadLine(); TransactionOptions transactionOptions = new TransactionOptions(); transactionOptions.IsolationLevel = IsolationLevel.RepeatableRead; transactionOptions.Timeout = new TimeSpan(0, 1, 0); using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew, transactionOptions)) { IDictionary <string, string> context = null; IContextManager contextManager = proxy.InnerChannel.GetProperty <IContextManager>(); if (context != null) { contextManager.SetContext(context); } proxy.AddItemToCart("BK-M18B-42"); if (context == null) { context = contextManager.GetContext(); } Console.WriteLine(proxy.GetShoppingCart()); proxy.RemoveItemFromCart("BK-R19B-44"); Console.WriteLine(proxy.GetShoppingCart()); if (proxy.Checkout()) { scope.Complete(); Console.WriteLine("Goods purchased."); } } Console.WriteLine(); // Disconnect from the service proxy.Close(); } catch (FaultException <SystemFault> sf) { Console.WriteLine("SystemFault {0}: {1}\n{2}", sf.Detail.SystemOperation, sf.Detail.SystemMessage, sf.Detail.SystemReason); } catch (FaultException <DatabaseFault> dbf) { Console.WriteLine("DatabaseFault {0}: {1}\n{2}", dbf.Detail.DbOperation, dbf.Detail.DbMessage, dbf.Detail.DbReason); } catch (FaultException e) { Console.WriteLine("{0}: {1}", e.Code.Name, e.Reason); } catch (Exception e) { Console.WriteLine("General exception: {0}", e.Message); Console.WriteLine("Inner Exception: {0}", e.InnerException); } Console.WriteLine("Press ENTER to continue"); Console.ReadLine(); }
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); } } }