Exemplo n.º 1
0
        public void UpdateInventory(UpdateInventoryMessage request)
        {
            try
            {
                InventoryStore.UpdateInventory(request.Body.ProductName, request.Body.Quantity);
            }
            catch (InventoryException)
            {
                InventoryFault fault = new InventoryFault();
                fault.Description = "Not enough units in stock";

                FaultException<InventoryFault> faultException = new FaultException<InventoryFault>(fault, "Inventory Error");
                throw faultException;
            }
        }
Exemplo n.º 2
0
        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();
            }
        }