0

How can I send and receive a LIST object via MSMQ in C#?

Hard to find suggestions.

Detail examples greatly appreciated.

shilovk
  • 11,718
  • 17
  • 75
  • 74

1 Answers1

0

To send the list, you may just do:

queue.Send(list);

To receive the list, use this:

queue.Formatter = new XmlMessageFormatter(new Type[]{typeof(List<T>)}); //Replace T with the type your list holds
Message message = queue.Receive();
List<T> list = (List<T>)message.Body;

When the message is sent, the object is formatted using XML. So, when receiving, you must specify that the queue uses a XML formatter with whatever type of list you have. Then, after receiving, the message's body must be casted to the list of the proper type.

Nolan
  • 175
  • 9
  • I'm not using WCF...so this answer above was the best – user3063679 Apr 02 '18 at 03:02
  • @user3063679 Mark it as best answer so that this thread can be closed. – Nolan Apr 02 '18 at 16:52
  • @user3063679 There should be a checkmark near the up and down arrows next to my answer. Click on that. For more info, visit https://stackoverflow.com/help/someone-answers. – Nolan Apr 03 '18 at 15:01
  • @user3063679 Are you going to mark it as best answer? Stack Overflow guidelines say not to just leave a post after it is answered, and instead mark the best answer. – Nolan Apr 03 '18 at 23:21
  • @user3063679 Read the link I sent you – Nolan Apr 04 '18 at 13:38