private static void PresentTotalAmount() { using (TransactionCreditService.Service1Client client = new TransactionCreditService.Service1Client()) { Console.WriteLine("Account 1: " + client.GetAccountDetails(1).ToString()); Console.WriteLine("Account 2: " + client.GetAccountDetails(2).ToString()); Console.WriteLine(""); } }
private static void PerformTransaction(string creditAccountID, string debitAccountID, double amount) { bool debitResult = false; bool creditResult = false; try { using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Suppress)) { #region Service Call #region Without Inner TransactionScope using (TransactionDebitService.Service1Client client = new TransactionDebitService.Service1Client()) { debitResult = client.PerformDebitTransaction(debitAccountID, amount); } throw new Exception(); using (TransactionCreditService.Service1Client client = new TransactionCreditService.Service1Client()) { creditResult = client.PerformCreditTransaction(creditAccountID, amount); } #endregion #region With Inner TransactionScope //using (TransactionScope tsInner = new TransactionScope()) //{ // using (TransactionDebitService.Service1Client client = new TransactionDebitService.Service1Client()) // { // debitResult = client.PerformDebitTransaction(debitAccountID, amount); // } // throw new Exception(); // using (TransactionCreditService.Service1Client client = new TransactionCreditService.Service1Client()) // { // creditResult = client.PerformCreditTransaction(creditAccountID, amount); // } // tsInner.Complete(); //} #endregion #endregion #region Client Call //using (TransactionScope tsInner = new TransactionScope()) //{ // debitResult = PerformDebitTransaction(debitAccountID, amount); // throw new Exception(); // creditResult = PerformCreditTransaction(creditAccountID, amount); // tsInner.Complete(); //} #endregion if (debitResult && creditResult) { // To commit the transaction ts.Complete(); } } } catch (Exception ex) { // rolling back } }