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!

Message Class

Provides access to the properties needed to define a Message Queuing message.

Object
   Component
      Message

[Visual Basic]
Public Class Message
   Inherits Component
[C#]
public class Message : Component
[C++]
public __gc class Message : public Component
[JScript]
public class Message extends Component

Remarks

When you send a message to a message queue, you don't have to always use the Message class, but it gives you more control over the System.Messaging.Message.Send property. For example, you can send a text message using the Send method of MessageQueue without instantiating a Message and assigning the string to the message Body; when you call Send, a Message Queuing message object (an instance of MSMQMessage) is created outside your application to wrap the text string.

Using Message enables you to access and modify the properties of the Message Queuing message object. You have more control over the object's behavior than when you let Message Queuing create a default MSMQMessage outside your application. You can specify encryption and authentication settings, capture sender information and define transaction contexts for your messages. You can also coordinate your messaging application to respond to acknowledgment and report messages in order to monitor your messages.

The message Body, in which the majority of the critical message information is stored, can be accessed both at creation time and throughout the lifetime of the Message instance. The Body is serialized using the Formatter specified, either for the MessageQueue instance or for the message itself. If it is serialized using the System.Messaging.XMLMessageFormatter, it is human-readable even while it is in the queue. If the body is serialized using another formatter (like the binary formatter), it is not human-readable between the time that it is written and the time it is received from the queue. However, binary formatters are useful because they provide faster message throughput.

When an instance of Message is created, some of the read/write properties are set to initial values. For a list of these values, see the Message constructor.

Requirements

Namespace: System.Messaging

Assembly: system.messaging.dll

Example [Visual Basic]

The following example creates an empty message. The example populates the Message with a string Body, and sets other properties. Then the message is sent to a queue. It assumes there is a queue on the computer "myComputer" with the name "myQueue".

The second procedure calls Peek on the first message in the queue "myQueue".

Import the System.Messaging namespace for this example.

[Visual Basic]

Private Sub CreateMessage()
    'Declare a message and message queue
    Dim msg As Message
    Dim mq As MessageQueue
    
    'Instantiate an empty message object
    msg = New Message
   
    'Instantiate a new MessageQueue object
    mq = New MessageQueue("myComputer\myQueue")

    'Set selected message properties.
    msg.Priority = MessagePriority.High
    msg.Label = "My Message"
    msg.TimeToBeReceived = New TimeSpan(1000)
    msg.TimeToReachQueue = New TimeSpan(1000)
    msg.Body = "New Message Body"
    'Send the message to the queue.
    mq.Send(msg)
End Sub

Private Sub PeekMessage()
    'Declare a message and message queue.
    Dim msg As Message
    Dim mq As MessageQueue
    'Set the MessageQueue to the queue in the above procedure, myQueue.
    mq = New MessageQueue("myComputer\myQueue")
    'Peek the first message in the queue.
    msg = mq.Peek
End Sub

See Also

Message Members | System.Messaging Namespace | MessageQueue | DefaultPropertiesToSend | Send | Receive | Peek