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 Simple Messages

Using an instance of the MessageQueue component, you can send simple messages to a queue in as little as two lines of code. When you send a simple message, you must perform the following actions:

Creating a Connection to the Queue

After you decide which queue you want to communicate with, you need to create an instance of the MessageQueue component that references the queue you want to use. You can create this component by using the MessageQueue constructor.

To create a connection to the queue you want to communicate with

  1. Create an instance of the MessageQueue component. For details, see Creating MessageQueue Components.
  2. Use the component's Path property to connect to the queue with which you want to communicate by the queue path, format name, or label.
    Note   If you created your component from Server Explorer, the Path property is set automatically to the queue path for that queue.

Providing the Data to Be Sent

Each MessageQueue component contains a series of default properties that are applied to all messages sent by that component, unless you specify otherwise in an individual message. In the simplest scenario, you can send a simple message to the queue using the default properties set for the component. For more information on these properties, see Default Message Properties.

You use the Send method to specify a message and send it to the queue. You can send objects, primitive data types, streams, and other kinds of data in a simple message.

The MessageQueue component takes the data you specify in the Send method's argument, persists it into a message, and sends the message to the specified queue.

Note   You can also use the Message object to send far more complex messages to a queue. In addition, you can send messages as part of a transaction. For more information, see Sending Complex Messages.

To send a simple message

  1. Accept the default value for the Formatter property, or set the property to XMLMessageFormatter if you have changed the default value.
  2. Use the Send method to send a simple message to your queue, specifying the message as an argument of the method.

    Your code to send a simple message might look like this:

    [Visual Basic]
    'Create a connection to the queue
    Dim MessageQueue1 as new MessageQueue ("YourMachine\YourQueue")
    'Send an integer
    MessageQueue1.Send(1)
    'Send a string
    MessageQueue1.Send("Hello world")
    'Persist an object and send it to the queue
    MessageQueue1.Send(System.DateTime.Now)
    [C#]
    // Create a connection to the queue
    MessageQueue mq = new MessageQueue (@"YourMachine\YourQueue");
    // Send an integer
    mq.Send (1);
    // Send a string
    mq.Send ("Hello world");
    // Persist an object and send it to the queue
    mq.Send (System.DateTime.Now);
    

See Also

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