NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Sending Complex Messages

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

  1. Create an instance of the MessageQueue component and set its Path property to the queue to which you want to refer. For details, see Creating MessageQueue Components.
  2. Create an instance of the Message object.
  3. Set the body of the message and specify any properties you want to change from their default values.
  4. Use the Send method to send your object to the queue.

    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);

See Also

Sending and Serializing Messages | Creating MessageQueue Components | Sending Simple Messages | Sending Messages Asynchronously | Transactional Message Processing