Introduction to Reading and Retrieving Messages

There are several considerations to keep in mind when reading and retrieving messages.

Locking Access to a Queue

When you perform a receive operation, you may want to temporarily prevent other users from also removing messages from the queue with which you are working. You can do this by setting the DenySharedReceive property on that queue to true. Setting DenySharedReceive prevents any other users from removing messages from the same queue until you release your usage of it, either through garbage collection or by calling the Close method.

Properties to Retrieve

Messages have a large number of properties, and filtering the properties you want to receive can enable you to focus on only the information that is relevant to you. For example, if you are not working with transactional messages, you might not want to retrieve the properties associated with transactions. In this case, you would set the MessagePropertyFilter properties IsFirstInTransaction , IsLastInTransaction, TransactionId, and TransactionStatusQueue to false. Your MessageQueue component instance would not retrieve any of the property values corresponding to these properties whenever it gets a message from a queue. For more information, see How to: Specify Properties to Retrieve with a Message.

Specifying the Format for Received Messages

When you read messages from a queue, a formatter object is used to serialize and deserialize the message's contents as you manipulate the message. By default, an XmlMessageFormatter object is associated with any instance of the MessageQueue component you create, and you can use this to receive messages by setting a few necessary properties on it. You can also use various other types of formatter objects that are available to you; for more information on the formatters available, see Message Serialization.

The XmlMessageFormatter persists objects and primitive data types into and out of messages using human-readable XML strings. When you want to use this formatter to retrieve a message, you set a TargetTypeNames or TargetTypes property to indicate how the resulting message should be handled. If you are using another formatter object, the properties differ.

See Also

Tasks

How to: Specify the Formatter for Retrieved Messages

How to: Receive Messages Programmatically

How to: Peek at Messages

Concepts

Asynchronous Message Processing

Message Serialization