예제 #1
0
        public void SendMessage()
        {
            Program.Order sentOrder = new Program.Order();
            sentOrder.orderId   = 3;
            sentOrder.orderTime = DateTime.Now;
            MessageQueue myQueue = new MessageQueue(".\\private$\\testConnect");

            myQueue.Send(sentOrder);
            myQueue.Send(sentOrder);
            return;
        }
예제 #2
0
        //**************************************************
        // Receives a message containing an Order.
        //**************************************************

        public void ReceiveMessage()
        {
            // Connect to the a queue on the local computer.
            MessageQueue myQueue = new MessageQueue(".\\private$\\testConnect");

            // Set the formatter to indicate body contains an Order.
            myQueue.Formatter = new XmlMessageFormatter(new Type[]
                                                        { typeof(Program.Order) });

            try
            {
                // Receive and format the message.
                Message       myMessage = myQueue.Receive();
                Program.Order myOrder   = (Program.Order)myMessage.Body;

                // Display message information.
                Console.WriteLine("Order ID: " +
                                  myOrder.orderId.ToString());
                Console.WriteLine("Sent: " +
                                  myOrder.orderTime.ToString());
            }

            catch (MessageQueueException)
            {
                // Handle Message Queuing exceptions.
            }

            // Handle invalid serialization format.
            catch (InvalidOperationException e)
            {
                Console.WriteLine(e.Message);
            }

            // Catch other exceptions as necessary.

            return;
        }