.NET Framework Developer Center >
.NET Development Forums
>
Common Language Runtime
>
Passing Winsock in Messagequeue
Passing Winsock in Messagequeue
- Hi,
I want to send a winsock object in messagequeue. I can send and receive string through messagequeue. In my application I need to send a winsock object. can U help me.......
Answers
- 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.- Marked As Answer byeryangMSFT, ModeratorMonday, November 09, 2009 6:43 AM
All Replies
- 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.- Marked As Answer byeryangMSFT, ModeratorMonday, November 09, 2009 6:43 AM


