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

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

            // Create a ServiceHost for the OrderStatus service type.
            using (ServiceHost serviceHost = new ServiceHost(typeof(OrderStatusService)))
            {
                // Open the ServiceHostBase to create listeners and start listening for order status messages.
                serviceHost.Open();

                // 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 client with given client endpoint configuration
                OrderProcessorClient client = new OrderProcessorClient("OrderProcessorEndpoint");

                //Create a transaction scope.
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    string hostName = Dns.GetHostName();

                    // Make a queued call to submit the purchase order
                    client.SubmitPurchaseOrder(po, "net.msmq://" + hostName + "/private/ServiceModelSamplesTwo-way/OrderStatus");

                    // Complete the transaction.
                    scope.Complete();
                }

                //Close down the client
                client.Close();

                Console.WriteLine();
                Console.WriteLine("Press <ENTER> to terminate client.");
                Console.ReadLine();
            }
        }
Exemple #2
0
        static void Main()
        {
            // Get MSMQ queue name from appsettings in configuration.
            string deadLetterQueueName = ConfigurationManager.AppSettings["deadLetterQueueName"];

            // Create the transacted MSMQ queue for storing dead message if necessary.
            if (!System.Messaging.MessageQueue.Exists(deadLetterQueueName))
            {
                System.Messaging.MessageQueue.Create(deadLetterQueueName, true);
            }

            OrderProcessorClient client = new OrderProcessorClient("OrderProcessorEndpoint");

            try
            {
                // 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);
                    // Complete the transaction.
                    scope.Complete();
                }

                client.Close();
            }
            catch (TimeoutException timeout)
            {
                Console.WriteLine(timeout.Message);
                client.Abort();
            }
            catch (CommunicationException conexcp)
            {
                Console.WriteLine(conexcp.Message);
                client.Abort();
            }

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
Exemple #3
0
        static void Main(string[] args)
        {
            //Connect to the queue
            MessageQueue orderQueue = new MessageQueue("FormatName:Direct=OS:" + ConfigurationManager.AppSettings["orderQueueName"]);

            // 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;

            // submit the purchase order
            Message msg = new Message();

            msg.Body  = po;
            msg.Label = "SubmitPurchaseOrder";

            //Submit an Order.
            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
            {
                orderQueue.Send(msg, MessageQueueTransactionType.Automatic);
                // Complete the transaction.
                scope.Complete();
            }
            Console.WriteLine("Placed the order:{0}", po);

            // submit the purchase order
            Message msg2 = new Message();

            msg2.Body  = po.poNumber;
            msg2.Label = "CancelPurchaseOrder";

            //Cancel the Order.
            using (TransactionScope scope2 = new TransactionScope(TransactionScopeOption.Required))
            {
                orderQueue.Send(msg2, MessageQueueTransactionType.Automatic);
                // Complete the transaction.
                scope2.Complete();
            }
            Console.WriteLine("Cancelled the Order: {0}", po.poNumber);
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
Exemple #4
0
        static void Main()
        {
            // Get MSMQ queue name from app settings in configuration
            string queueName = ConfigurationManager.AppSettings["queueName"];

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

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

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

                // 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 client with given client endpoint configuration
                OrderProcessorClient client = new OrderProcessorClient("OrderProcessorEndpoint");

                //Create a transaction scope.
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    string hostName = Dns.GetHostName();

                    // Make a queued call to submit the purchase order
                    client.SubmitPurchaseOrder(po, "net.msmq://" + hostName + "/private/ServiceModelSamplesTwo-way/OrderStatus");

                    // Complete the transaction.
                    scope.Complete();
                }

                //Close down the client
                client.Close();

                Console.WriteLine();
                Console.WriteLine("Press <ENTER> to terminate client.");
                Console.ReadLine();
            }
        }
Exemple #5
0
        static void Main(string[] args)
        {
            //Connect to the queue
            MessageQueue orderQueue = new MessageQueue("FormatName:Direct=OS:" + ConfigurationManager.AppSettings["orderQueueName"]);

            // 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;

            // submit the purchase order
            Message msg = new Message();
            msg.Body = po;
            msg.Label = "SubmitPurchaseOrder";

            //Submit an Order.
            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
            {
                
                orderQueue.Send(msg, MessageQueueTransactionType.Automatic);
                // Complete the transaction.
                scope.Complete();
                
            }
            Console.WriteLine("Placed the order:{0}", po);

            // submit the purchase order
            Message msg2 = new Message();
            msg2.Body = po.poNumber;
            msg2.Label = "CancelPurchaseOrder";

            //Cancel the Order.
            using (TransactionScope scope2 = new TransactionScope(TransactionScopeOption.Required))
            {
                
                orderQueue.Send(msg2, MessageQueueTransactionType.Automatic);
                // Complete the transaction.
                scope2.Complete();
               
            }
            Console.WriteLine("Cancelled the Order: {0}", po.poNumber);
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
Exemple #6
0
        static void Main()
        {
            try
            {
                // Create a client with given client endpoint configuration
                OrderProcessorClient client = new OrderProcessorClient("OrderProcessorEndpoint");

                // send 10 purchase orders
                for (int i = 0; i < 10; i++)
                {
                    // 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);


                        // Complete the transaction.
                        scope.Complete();
                    }

                }

                client.Close();

                Console.WriteLine();
                Console.WriteLine("Press <ENTER> to terminate client.");
                Console.ReadLine();
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: {0}", e);
            }
        }
Exemple #7
0
        static void Main()
        {
            try
            {
                // Create a client with given client endpoint configuration
                OrderProcessorClient client = new OrderProcessorClient("OrderProcessorEndpoint");

                // send 10 purchase orders
                for (int i = 0; i < 10; i++)
                {
                    // 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);


                        // Complete the transaction.
                        scope.Complete();
                    }
                }

                client.Close();

                Console.WriteLine();
                Console.WriteLine("Press <ENTER> to terminate client.");
                Console.ReadLine();
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: {0}", e);
            }
        }
Exemple #8
0
        static void Main()
        {
            // Create a proxy with given client endpoint configuration.
            OrderProcessorClient wcfClient = new OrderProcessorClient("OrderProcessorEndpoint");

            try
            {
                // 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.
                    wcfClient.SubmitPurchaseOrder(po);
                    // Complete the transaction.
                    scope.Complete();
                }
            }
            catch (TimeoutException timeProblem)
            {
                Console.WriteLine("The service operation timed out. " + timeProblem.Message);
                Console.ReadLine();
                wcfClient.Abort();
            }
            catch (CommunicationException commProblem)
            {
                Console.WriteLine("There was a communication problem. " + commProblem.Message + commProblem.StackTrace);
                Console.ReadLine();
                wcfClient.Abort();
            }
            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
Exemple #9
0
        static void Main()
        {
            // Get MSMQ queue name from app settings in configuration
            string deadLetterQueueName = ConfigurationManager.AppSettings["deadLetterQueueName"];

            // Create the transacted MSMQ queue for storing dead message if necessary.
            if (!MessageQueue.Exists(deadLetterQueueName))
                MessageQueue.Create(deadLetterQueueName, true);

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

            // 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);
                // Complete the transaction.
                scope.Complete();
            }

            client.Close();

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
Exemple #10
0
        static void Main()
        {
            // Create a client.
            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;

            // <Snippet8>
            //Create a transaction scope.
            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
            {
                // Make a queued call to submit the purchase order.
                client.SubmitPurchaseOrder(po);
                // Complete the transaction.
                scope.Complete();
            }

            //Closing the client gracefully closes the connection and cleans up resources.
            client.Close();
            // </Snippet8>

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
Exemple #11
0
        static void Main(string[] args)
        {
            // <Snippet4>
            // 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;

            OrderProcessorClient        client   = new OrderProcessorClient("OrderResponseEndpoint");
            MsmqMessage <PurchaseOrder> ordermsg = new MsmqMessage <PurchaseOrder>(po);

            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
            {
                client.SubmitPurchaseOrder(ordermsg);
                scope.Complete();
            }

            Console.WriteLine("Order has been submitted:{0}", po);

            //Closing the client gracefully closes the connection and cleans up resources.
            client.Close();

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
            // </Snippet4>
        }
Exemple #12
0
        static void PlaceOrder()
        {
            //Connect to the queue
            MessageQueue orderQueue = new MessageQueue("FormatName:Direct=OS:" + ConfigurationManager.AppSettings["orderQueueName"]);

            // 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;

            Message msg = new Message();

            msg.UseDeadLetterQueue = true;
            msg.Body = po;

            //Create a transaction scope.
            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
            {
                // submit the purchase order
                orderQueue.Send(msg, MessageQueueTransactionType.Automatic);
                // Complete the transaction.
                scope.Complete();
            }
            //Save the string for orderResponse correlation
            orderMessageID = msg.Id;
            Console.WriteLine("Placed the order, waiting for response...");
        }
Exemple #13
0
        static void Main()
        {
            Random randomGen = new Random();

            for (int i = 0; i < 2500; i++)
            {
                // Create a client with given client endpoint configuration
                OrderProcessorClient client = new OrderProcessorClient("OrderProcessorEndpoint");

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

                PurchaseOrderLineItem lineItem1 = new PurchaseOrderLineItem();
                lineItem1.ProductId = "Blue Widget";
                lineItem1.Quantity  = randomGen.Next(1, 100);
                lineItem1.UnitCost  = (float)randomGen.NextDouble() * 10;

                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);
                    // Complete the transaction.
                    scope.Complete();
                }

                client.Close();
            }
            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
Exemple #14
0
        static void Main()
        {
            Random randomGen = new Random();
            for (int i = 0; i < 2500; i++)
            {
                // Create a client with given client endpoint configuration
                OrderProcessorClient client = new OrderProcessorClient("OrderProcessorEndpoint");

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

                PurchaseOrderLineItem lineItem1 = new PurchaseOrderLineItem();
                lineItem1.ProductId = "Blue Widget";
                lineItem1.Quantity = randomGen.Next(1, 100);
                lineItem1.UnitCost = (float)randomGen.NextDouble() * 10;

                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);
                    // Complete the transaction.
                    scope.Complete();
                }

                client.Close();
            }
            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
Exemple #15
0
        static void PlaceOrder()
        {
            //Connect to the queue
            MessageQueue orderQueue = new MessageQueue("FormatName:Direct=OS:" + ConfigurationManager.AppSettings["orderQueueName"]);

            // 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;

            Message msg = new Message();
            msg.UseDeadLetterQueue = true;
            msg.Body = po;

            //Create a transaction scope.
            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
            {
                // submit the purchase order
                orderQueue.Send(msg, MessageQueueTransactionType.Automatic);
                // Complete the transaction.
                scope.Complete();
                
            }
            //Save the string for orderResponse correlation
            orderMessageID = msg.Id;
            Console.WriteLine("Placed the order, waiting for response...");
        }
Exemple #16
0
        static void Main()
        {
            // Create a client
            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);
                // Complete the transaction.
                scope.Complete();
            }

            //Closing the client gracefully closes the connection and cleans up resources
            client.Close();

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
Exemple #17
0
        public static void Snippet2()
        {
            // <Snippet2>
            MsmqIntegrationBinding           binding        = new MsmqIntegrationBinding();
            EndpointAddress                  address        = new EndpointAddress("msmq.formatname:DIRECT=OS:.\\private$\\Orders");
            ChannelFactory <IOrderProcessor> channelFactory = new ChannelFactory <IOrderProcessor>(binding, address);
            IOrderProcessor                  channel        = channelFactory.CreateChannel();

            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;


            MsmqMessage <PurchaseOrder> ordermsg = new MsmqMessage <PurchaseOrder>(po);

            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
            {
                channel.SubmitPurchaseOrder(ordermsg);
                scope.Complete();
            }
            Console.WriteLine("Order has been submitted:{0}", po);
            // </Snippet2>
        }
Exemple #18
0
        static void Main(string[] args)
        {
            // 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;

            OrderProcessorClient client = new OrderProcessorClient("OrderResponseEndpoint");

            MsmqMessage<PurchaseOrder> ordermsg = new MsmqMessage<PurchaseOrder>(po);
            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
            {
                client.SubmitPurchaseOrder(ordermsg);
                scope.Complete();
            }
            Console.WriteLine("Order has been submitted:{0}", po);

            //Closing the client gracefully closes the connection and cleans up resources
            client.Close();

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
Exemple #19
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/ServiceModelSamples/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");
            }

        }
Exemple #20
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/ServiceModelSamples/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");
            }
        }