public void ChargeAccount(ChargeAccountMessage request) { try { AccountStore.Debit(request.Body.Balance); } catch (CreditExceededException) { AccountingFault fault = new AccountingFault(); fault.Description = "You exceeded your credit"; FaultException<AccountingFault> faultException = new FaultException<AccountingFault>(fault, "Accounting Errror"); throw faultException; } }
public void PlaceOrder(OrderMessage request) { using (TransactionScope scope = new TransactionScope()) using (ChannelWrapper<IPetShopInventoryService> inventory = new ChannelWrapper<IPetShopInventoryService>("Inventory")) using (ChannelWrapper<IPetShopAccountingService> accounting = new ChannelWrapper<IPetShopAccountingService>("Accounting")) { // update account int total = CalculateTotal(request.Body.ProductName, request.Body.Quantity); Account account = new Account(); account.Balance = total; ChargeAccountMessage accountingMsg = new ChargeAccountMessage(); accountingMsg.Body = account; try { accounting.Channel.ChargeAccount(accountingMsg); } catch (FaultException<AccountingFault> ex) { OrderFault fault = new OrderFault(); fault.Description = ex.Detail.Description; throw new FaultException<OrderFault>(fault, "Order failed"); } // update inventory UpdateInventoryMessage inventoryMsg = new UpdateInventoryMessage(); inventoryMsg.Body = request.Body; try { inventory.Channel.UpdateInventory(inventoryMsg); } catch (FaultException<InventoryFault> ex) { OrderFault fault = new OrderFault(); fault.Description = ex.Detail.Description; throw new FaultException<OrderFault>(fault, "Order failed"); } scope.Complete(); } }