In addition to sending a simple message by specifying your message in the Send method's argument, you can gain more control over your messages by explicitly creating a Message object, rather than letting the shared Send method create and send one for you. By manipulating the properties of the resulting Message object, you can create more complex messages and exert more control over the way your messages are handled.
When you send a complex message, you must first create a connection to the queue with which you want to communicate, and then specify the data to send. However, as part of specifying the data to send, you will create an instance of the Message class, set the properties you need, and fine-tune the delivery mechanisms before sending your message. As with simple messages, the system persists your message object and sends it to the queue you specified.
For more information on the properties you can use to fine-tune your Message object, see Message Members.
Note Using the Message object, you can send messages as part of a transaction. For more information, see Transactional Message Processing.
To send a complex message using the Message class
When you're finished, your code might look like this:
[Visual Basic] Dim newMessage as System.Messaging.MessageQueue.Message newMessage = new Message("Hello again") newMessage.Label = "This is the label" MessageQueue1.Send(newMessage) [C#] System.Messaging.MessageQueue.Message newMessage; newMessage = new System.Messaging.MessageQueue.Message("Hello again"); newMessage.Label = "This is the label"; MessageQueue1.Send (newMessage);
Sending and Serializing Messages | Creating MessageQueue Components | Sending Simple Messages | Sending Messages Asynchronously | Transactional Message Processing