示例#1
0
        static void Main()
        {
            // Get MSMQ queue name from app settings in configuration
            string targetQueueName = ConfigurationManager.AppSettings["targetQueueName"];

            // Create the transacted MSMQ queue if necessary.
            // This is the queue the order status would be reported to
            if (!MessageQueue.Exists(targetQueueName))
            {
                MessageQueue.Create(targetQueueName, true);
            }

            // Get MSMQ queue name from app settings in configuration
            string responseQueueName = ConfigurationManager.AppSettings["responseQueueName"];

            // Create the transacted MSMQ queue if necessary.
            // This is the queue the order status would be reported to
            if (!MessageQueue.Exists(responseQueueName))
            {
                MessageQueue.Create(responseQueueName, true);
            }


            // Create a ServiceHost for the OrderStatus service type.
            ServiceHost serviceHost = new ServiceHost(typeof(OrderStatusService));

            // Open the ServiceHostBase to create listeners and start listening for order status messages.
            serviceHost.Open();

            // Create a proxy with given client endpoint configuration
            OrderProcessorClient client = new OrderProcessorClient();

            // Create the purchase order
            PurchaseOrder po = new PurchaseOrder();

            po.CustomerId = "somecustomer.com";
            po.PONumber   = Guid.NewGuid().ToString();

            PurchaseOrderLineItem lineItem1 = new PurchaseOrderLineItem();

            lineItem1.ProductId = "Blue Widget";
            lineItem1.Quantity  = 54;
            lineItem1.UnitCost  = 29.99F;

            PurchaseOrderLineItem lineItem2 = new PurchaseOrderLineItem();

            lineItem2.ProductId = "Red Widget";
            lineItem2.Quantity  = 890;
            lineItem2.UnitCost  = 45.89F;

            po.orderLineItems    = new PurchaseOrderLineItem[2];
            po.orderLineItems[0] = lineItem1;
            po.orderLineItems[1] = lineItem2;

            //Create a transaction scope.
            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
            {
                // Make a queued call to submit the purchase order
                client.SubmitPurchaseOrder(po, "net.msmq://localhost/private/ServiceModelSamplesOrder/OrderStatus");
                // Complete the transaction.
                scope.Complete();
            }

            //Closing the client gracefully closes the connection and cleans up resources
            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();

            client.Close();

            try
            {
                serviceHost.Close();
            }
            catch (CommunicationObjectFaultedException)
            {
                Console.WriteLine("Warning: the order status service is in faulted state");
            }
        }
示例#2
0
        static void Main()
        {
            // Get MSMQ queue name from app settings in configuration
            string targetQueueName = ConfigurationManager.AppSettings["targetQueueName"];

            // Create the transacted MSMQ queue if necessary.
            // This is the queue the order status would be reported to
            if (!MessageQueue.Exists(targetQueueName))
                MessageQueue.Create(targetQueueName, true);

            // Get MSMQ queue name from app settings in configuration
            string responseQueueName = ConfigurationManager.AppSettings["responseQueueName"];

            // Create the transacted MSMQ queue if necessary.
            // This is the queue the order status would be reported to
            if (!MessageQueue.Exists(responseQueueName))
                MessageQueue.Create(responseQueueName, true);


            // Create a ServiceHost for the OrderStatus service type.
            ServiceHost serviceHost = new ServiceHost(typeof(OrderStatusService));

            // Open the ServiceHostBase to create listeners and start listening for order status messages.
            serviceHost.Open();

            // Create a proxy with given client endpoint configuration
            OrderProcessorClient client = new OrderProcessorClient();

            // Create the purchase order
            PurchaseOrder po = new PurchaseOrder();
            po.CustomerId = "somecustomer.com";
            po.PONumber = Guid.NewGuid().ToString();

            PurchaseOrderLineItem lineItem1 = new PurchaseOrderLineItem();
            lineItem1.ProductId = "Blue Widget";
            lineItem1.Quantity = 54;
            lineItem1.UnitCost = 29.99F;

            PurchaseOrderLineItem lineItem2 = new PurchaseOrderLineItem();
            lineItem2.ProductId = "Red Widget";
            lineItem2.Quantity = 890;
            lineItem2.UnitCost = 45.89F;

            po.orderLineItems = new PurchaseOrderLineItem[2];
            po.orderLineItems[0] = lineItem1;
            po.orderLineItems[1] = lineItem2;

            //Create a transaction scope.
            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
            {
                // Make a queued call to submit the purchase order
                client.SubmitPurchaseOrder(po, "net.msmq://localhost/private/ServiceModelSamplesOrder/OrderStatus");
                // Complete the transaction.
                scope.Complete();
            }

            //Closing the client gracefully closes the connection and cleans up resources
            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();

            client.Close();

            try
            {
                serviceHost.Close();
            }
            catch (CommunicationObjectFaultedException)
            {
                Console.WriteLine("Warning: the order status service is in faulted state");
            }
        }
示例#3
0
 public void SubmitPurchaseOrder(PurchaseOrder po, string reportOrderStatusTo)
 {
     Orders.Add(po);
     Console.WriteLine("Processing {0} ", po);
     Console.WriteLine("Sending back order status information");
     NetMsmqBinding msmqCallbackBinding = new NetMsmqBinding();
     msmqCallbackBinding.Security.Mode = NetMsmqSecurityMode.None;
     OrderStatusClient client = new OrderStatusClient(msmqCallbackBinding, new EndpointAddress(reportOrderStatusTo));
     // please note that the same transaction that is used to dequeue purchase order is used
     // to send back order status
     using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
     {
         client.OrderStatus(po.PONumber, po.Status);
         scope.Complete();
     }
 }
示例#4
0
 public static void Add(PurchaseOrder po)
 {
     purchaseOrders.Add(po.PONumber, po);
 }
示例#5
0
 public static void Add(PurchaseOrder po)
 {
     purchaseOrders.Add(po.PONumber, po);
 }