當前位置: 首頁>>代碼示例>>C#>>正文


C# ChannelFactory.GetOrderAsync方法代碼示例

本文整理匯總了C#中System.ServiceModel.ChannelFactory.GetOrderAsync方法的典型用法代碼示例。如果您正苦於以下問題:C# ChannelFactory.GetOrderAsync方法的具體用法?C# ChannelFactory.GetOrderAsync怎麽用?C# ChannelFactory.GetOrderAsync使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.ServiceModel.ChannelFactory的用法示例。


在下文中一共展示了ChannelFactory.GetOrderAsync方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Main

        static void Main(string[] args)
        {
            Console.WriteLine("Press Enter to start");
            Console.ReadLine();

            ICustomerService customerService = new ChannelFactory<ICustomerService>("customerService").CreateChannel();
            IOrderService orderService = new ChannelFactory<IOrderService>("orderService").CreateChannel();

            using ((IDisposable)customerService)
            using ((IDisposable)orderService)
            {
                try
                {
                    // Get customers
                    Console.WriteLine("Customers:");
                    IEnumerable<Customer> customers = customerService.GetCustomersAsync().Result;
                    if (customers == null) return;
                    foreach (var c in customers)
                        PrintCustomer(c);

                    // Get orders for a customer
                    Console.WriteLine("\nGet customer orders {CustomerId}:");
                    string customerId = Console.ReadLine();
                    if (!customers.Any(c => string.Equals(c.CustomerId, customerId, StringComparison.OrdinalIgnoreCase)))
                    {
                        Console.WriteLine("Invalid customer id: {0}", customerId.ToUpper());
                        return;
                    }
                    IEnumerable<Order> orders = orderService.GetCustomerOrdersAsync(customerId).Result;
                    foreach (var o in orders)
                        PrintOrder(o);

                    // Get an order
                    Console.WriteLine("\nGet an order {OrderId}:");
                    int orderId = int.Parse(Console.ReadLine());
                    if (!orders.Any(o => o.OrderId == orderId))
                    {
                        Console.WriteLine("Invalid order id: {0}", orderId);
                        return;
                    }
                    Order order = orderService.GetOrderAsync(orderId).Result;
                    PrintOrderWithDetails(order);

                    // Create a new order
                    Console.WriteLine("\nPress Enter to create a new order for {0}",
                        customerId.ToUpper());
                    Console.ReadLine();

                    var newOrder = new Order
                    {
                        CustomerId = customerId,
                        OrderDate = DateTime.Today,
                        ShippedDate = DateTime.Today.AddDays(1),
                        OrderDetails = new ChangeTrackingCollection<OrderDetail>
                            {
                                new OrderDetail { ProductId = 1, Quantity = 5, UnitPrice = 10 },
                                new OrderDetail { ProductId = 2, Quantity = 10, UnitPrice = 20 },
                                new OrderDetail { ProductId = 4, Quantity = 40, UnitPrice = 40 }
                            }
                    };
                    var createdOrder = orderService.CreateOrderAsync(newOrder).Result;
                    PrintOrderWithDetails(createdOrder);

                    // Update the order
                    Console.WriteLine("\nPress Enter to update order details");
                    Console.ReadLine();

                    // Start change-tracking the order
                    var changeTracker = new ChangeTrackingCollection<Order>(createdOrder);

                    // Modify order details
                    createdOrder.OrderDetails[0].UnitPrice++;
                    createdOrder.OrderDetails.RemoveAt(1);
                    createdOrder.OrderDetails.Add(new OrderDetail
                    {
                        OrderId = createdOrder.OrderId,
                        ProductId = 3,
                        Quantity = 15,
                        UnitPrice = 30
                    });

                    // Submit changes
                    Order changedOrder = changeTracker.GetChanges().SingleOrDefault();
                    Order updatedOrder = orderService.UpdateOrderAsync(changedOrder).Result;

                    // Merge changes
                    changeTracker.MergeChanges(updatedOrder);
                    Console.WriteLine("Updated order:");
                    PrintOrderWithDetails(createdOrder);

                    // Delete the order
                    Console.WriteLine("\nPress Enter to delete the order");
                    Console.ReadLine();
                    bool deleted = orderService.DeleteOrderAsync(createdOrder.OrderId).Result;

                    // Verify order was deleted
                    Order deletedOrder = orderService.GetOrderAsync(createdOrder.OrderId).Result;
                    Console.WriteLine(deleted && deletedOrder == null
                        ? "Order was successfully deleted"
                        : "Order was not deleted");
//.........這裏部分代碼省略.........
開發者ID:luboshl,項目名稱:trackable-entities,代碼行數:101,代碼來源:Program.cs


注:本文中的System.ServiceModel.ChannelFactory.GetOrderAsync方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。