public void PlaceOrder(Order order)
        {
            _messageQueue.Send(new Messages.PlaceOrder
            {
                OrderId = order.OrderId,
                OrderDate = order.OrderDate,
                CustomerName = order.CustomerName,
                CustomerAddress = order.CustomerAddress,
                Lines = order.Lines.Select(l =>
                    new Messages.Line
                    {
                        ProductNumber = l.ProductNumber,
                        Quantity = l.Quantity
                    })
                    .ToList()
            });

            if (_networkError.Next(100) < 20)
                throw new FaultException<FulfillmentNetworkError>(
                    new FulfillmentNetworkError(),
                    "Network error.");
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            List<Guid> orderIds = new List<Guid>();

            ServiceClient<IFulfillmentService> client =
                new ServiceClient<IFulfillmentService>();
            var order = new Order
            {
                CustomerName = "Sherlock Holmes",
                CustomerAddress = "121B Baker Street",
                OrderDate = DateTime.Today,
                Lines = new List<Line>
                {
                    new Line
                    {
                        ProductNumber = 11190,
                        Quantity = 1
                    }
                }
            };

            for (int i = 0; i < 100; ++i)
            {
                Console.WriteLine("Place order {0}.", i);

                order.OrderId = Guid.NewGuid();
                PlaceOrder(client, order);
                orderIds.Add(order.OrderId);

                CheckPendingOrders(client, orderIds);
            }

            while (orderIds.Any())
                CheckPendingOrders(client, orderIds);

            Console.WriteLine("Finished");
            Console.ReadKey();
        }
Ejemplo n.º 3
0
 private static void PlaceOrder(
     ServiceClient<IFulfillmentService> client,
     Order order)
 {
     while (true)
     {
         try
         {
             client.CallService(
                 "BasicHttpBinding_IFulfillmentService",
                 s => s.PlaceOrder(order));
             return;
         }
         catch (Exception ex)
         {
             Console.WriteLine("Network error: retry.");
         }
     }
 }