Send a Custom Message Object Through Message Queuing

Problem

You want to send a custom object to another application via a message queue.

Solution

Create a serializable class that has a zero-argument constructor and includes no read-only properties. Wrap an instance of this class in a Message object and pass the Message object to the MessageQueue.Send method.

Discussion

Message queues accept simple text messages and custom .NET objects. In order to use a custom object, it must satisfy three criteria:

  • The class must have a public constructor with no arguments. .NET uses this constructor to re-create the object when the message is received.

  • The class must be marked with the Serializable attribute.

  • All class properties must be readable and writable. Read-only ...

Get Microsoft® Visual Basic® .NET Programmer's Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.