MessageQueue.ReceiveByCorrelationId Method (String, MessageQueueTransactionType)
Receives the message that matches the given correlation identifier and immediately raises an exception if no message with the specified correlation identifier currently exists in the queue.
Assembly: System.Messaging (in System.Messaging.dll)
member ReceiveByCorrelationId : correlationId:string * transactionType:MessageQueueTransactionType -> Message
The correlationId parameter is a null reference (Nothing in Visual Basic).
The message with the specified correlationId could not be found.
The transactionType parameter is not one of the MessageQueueTransactionType members.
An error occurred when accessing a Message Queuing method.
This method looks in the queue referenced by the MessageQueue for a message whose CorrelationId matches the specified correlationId parameter. If no message is found that matches the correlationID parameter, an exception is thrown. Otherwise, the message is removed from the queue and returned to the application using a transaction context defined by the transactionType parameter.
Specify Automatic for the transactionType parameter if there is already an external transaction context attached to the thread that you want to use to receive the message. Specify Single if you want to receive the message as a single internal transaction. You can specify None if you want to receive a message from a transactional queue outside of a transaction context.
If this method is called to receive a message from a transactional queue, the message that is received would be returned to the queue if the transaction is aborted. The message is not permanently removed from the queue until the transaction is committed.
The CorrelationId property is used to tie a message sent to the queue to associated response, report, or acknowledgment messages.
Two other methods allow you to receive messages from a queue. The Receive method returns the first message in the queue, and the ReceiveById(String) method is used to retrieve a message by specifying its unique identifier.
To read a message with a specified correlation identifier without removing it from the queue, use the PeekByCorrelationId(String) method. The PeekByCorrelationId(String) method always returns the first message in the queue, so subsequent calls to the method return the same message unless a higher priority message arrives in the queue. There is no transaction context associated with a message returned by a call to PeekByCorrelationId(String). Because PeekByCorrelationId(String) does not remove any messages in the queue, there would be nothing to roll back if the transaction were aborted.
The following table shows whether this method is available in various Workgroup modes.
Local computer and direct format name
Remote computer and direct format name
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.
Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)