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!

Retrieving Messages

You can use either static or dynamic retrieval mechanisms to retrieve a list of messages. When you retrieve a static list of messages, an array of Message objects representing all messages in the queue is returned. When you retrieve a dynamic list of messages, a MessagesEnumerator object representing all messages in the queue is returned.

To retrieve a static list of messages

  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 array that references the Message class to hold the results of your query.
  3. Call the GetAllMessages method.
  4. Assign the results to the array you created. Your code might look like this:
    [Visual Basic]
    Dim mq as New MessageQueue 
    Dim msg() as Message
    mq.Path = ".\MyQueue"
    msg = mq.GetAllMessages()
    For I = 0 to uBound(msg)
      Debug.Print msg(i).Body
    Next i
    [C#]
    MessageQueue mq = new MessageQueue();
    Message[] msg();
    mq.Path = @".\MyQueue";
    msg = mq.GetAllMessages();

To retrieve a dynamic list of messages

  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 a MessagesEnumerator object to hold the results of your query.
  3. Call the GetMessagesEnumerator method on the MessageQueue class.
  4. Assign the results to the MessagesEnumerator object. Your code might look like this:
    [Visual Basic]
    Sub Main
       Dim mq as New MessageQueue 
       Dim msgEnum As MessagesEnumerator
       mq.Path = ".\MyQueue"
       msqEnum = mq.GetMessagesEnumerator
    End Sub
    [C#]
    public void Main() {
       MessageQueue mq = new MessageQueue();
       MessagesEnumerator msgEnum;
       mq.Path = @".\MyQueue";
       msqEnum = mq.GetMessagesEnumerator();
    }

See Also

Queue and Message Collections | Retrieving Queues