Ask a questionAsk a question
 

AnswerPassing Winsock in Messagequeue

Answers

  • Friday, November 06, 2009 8:18 AMeryangMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi,
    Yes, we can send object through message queue by using Formatter . consider this type:
                public class Order
                {
                    public int orderId;
                    public DateTime orderTime;
                }   

    following code shows how to send an object of Order type and converts received message to correct type:
                // Creates a queue.
                string path = @".\myMSMQ";
                if (!MessageQueue.Exists(path))
                {
                    MessageQueue.Create(path);
                }

                // Sender sends the messge.
                MessageQueue sendQueue = new MessageQueue(path);
                Order order = new Order();
                order.orderId = 10;
                order.orderTime = new DateTime(2000, 10, 10);
                sendQueue.Send(order);


                // Receiver receives the message, and Formatter helps to convert the message body to your type.
                MessageQueue receiveQueue = new MessageQueue(path);
                receiveQueue.Formatter = new XmlMessageFormatter(new Type[] { typeof(Order) });
                System.Messaging.Message message = receiveQueue.Receive();
                Order myOrder = message.Body as Order;


    Thanks,
    Eric
    Please remember to mark helpful replies as answers and unmark them if they provide no help.

All Replies

  • Friday, November 06, 2009 8:18 AMeryangMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi,
    Yes, we can send object through message queue by using Formatter . consider this type:
                public class Order
                {
                    public int orderId;
                    public DateTime orderTime;
                }   

    following code shows how to send an object of Order type and converts received message to correct type:
                // Creates a queue.
                string path = @".\myMSMQ";
                if (!MessageQueue.Exists(path))
                {
                    MessageQueue.Create(path);
                }

                // Sender sends the messge.
                MessageQueue sendQueue = new MessageQueue(path);
                Order order = new Order();
                order.orderId = 10;
                order.orderTime = new DateTime(2000, 10, 10);
                sendQueue.Send(order);


                // Receiver receives the message, and Formatter helps to convert the message body to your type.
                MessageQueue receiveQueue = new MessageQueue(path);
                receiveQueue.Formatter = new XmlMessageFormatter(new Type[] { typeof(Order) });
                System.Messaging.Message message = receiveQueue.Receive();
                Order myOrder = message.Body as Order;


    Thanks,
    Eric
    Please remember to mark helpful replies as answers and unmark them if they provide no help.