Export (0) Print
Expand All

MessageQueue.MessageReadPropertyFilter Property

Gets or sets the property filter for receiving or peeking messages.

Namespace:  System.Messaging
Assembly:  System.Messaging (in System.Messaging.dll)

[MessagingDescriptionAttribute("MQ_MessageReadPropertyFilter")]
[BrowsableAttribute(false)]
public MessagePropertyFilter MessageReadPropertyFilter { get; set; }

Property Value

Type: System.Messaging.MessagePropertyFilter
The MessagePropertyFilter used by the queue to filter the set of properties it receives or peeks for each message.

ExceptionCondition
ArgumentException

The filter is null.

This filter is a set of Boolean values restricting the message properties that the MessageQueue receives or peeks. When the MessageQueue receives or peeks a message from the server queue, it retrieves only those properties for which the MessageReadPropertyFilter value is true.

The following shows initial property values for the MessageReadPropertyFilter property. These settings are identical to calling SetDefaults on a MessagePropertyFilter.

The following table shows whether this property is available in various Workgroup modes.

Workgroup mode

Available

Local computer

Yes

Local computer and direct format name

Yes

Remote computer

Yes

Remote computer and direct format name

Yes

The following code example uses the MessageReadPropertyFilter to restrict the message properties received.

using System;
using System.Messaging;

namespace MyProject
{
	/// <summary> 
	/// Provides a container class for the example. 
	/// </summary> 
	public class MyNewQueue
	{

		//************************************************** 
		// Provides an entry point into the application. 
		//		  
		// This example retrieves specific groups of Message 
		// properties. 
		//************************************************** 

		public static void Main()
		{
			// Create a new instance of the class.
			MyNewQueue myNewQueue = new MyNewQueue();

			// Retrieve specific sets of Message properties.
			myNewQueue.RetrieveDefaultProperties();
			myNewQueue.RetrieveAllProperties();
			myNewQueue.RetrieveSelectedProperties();

			return;
		}


		//************************************************** 
		// Retrieves the default properties for a Message. 
		//************************************************** 
		
		public void RetrieveDefaultProperties()
		{

			// Connect to a message queue.
			MessageQueue myQueue = new MessageQueue(".\\myQueue");

			// Specify to retrieve the default properties only.
			myQueue.MessageReadPropertyFilter.SetDefaults();

			// Set the formatter for the Message.
			myQueue.Formatter = new XmlMessageFormatter(new Type[]
				{typeof(String)});

			// Receive the first message in the queue.
			Message myMessage = myQueue.Receive();

			// Display selected properties.
			Console.WriteLine("Label: " + myMessage.Label);
			Console.WriteLine("Body: " + (String)myMessage.Body);
	
			return;
		}


		//************************************************** 
		// Retrieves all properties for a Message. 
		//************************************************** 
		
		public void RetrieveAllProperties()
		{

			// Connect to a message queue.
			MessageQueue myQueue = new MessageQueue(".\\myQueue");

			// Specify to retrieve all properties.
			myQueue.MessageReadPropertyFilter.SetAll();

			// Set the formatter for the Message.
			myQueue.Formatter = new XmlMessageFormatter(new Type[]
				{typeof(String)});

			// Receive the first message in the queue.
			Message myMessage = myQueue.Receive();

			// Display selected properties.
			Console.WriteLine("Encryption algorithm: " + 
				myMessage.EncryptionAlgorithm.ToString());
			Console.WriteLine("Body: " + (String)myMessage.Body);
	
			return;
		}
			

		//************************************************** 
		// Retrieves application-specific properties for a 
		// Message. 
		//************************************************** 
		
		public void RetrieveSelectedProperties()
		{
			// Connect to a message queue.
			MessageQueue myQueue = new MessageQueue(".\\myQueue");

			// Specify to retrieve selected properties.
			MessagePropertyFilter myFilter = new 
				MessagePropertyFilter();
			myFilter.ClearAll();
			// The following list is a random subset of available properties.
			myFilter.Body = true;
			myFilter.Label = true;
			myFilter.MessageType = true;
			myFilter.Priority = true;
			myQueue.MessageReadPropertyFilter = myFilter;

			// Set the formatter for the Message.
			myQueue.Formatter = new XmlMessageFormatter(new Type[]
				{typeof(String)});

			// Receive the first message in the queue.
			Message myMessage = myQueue.Receive();

			// Display selected properties.
			Console.WriteLine("Message type: " + 
				myMessage.MessageType.ToString());
			Console.WriteLine("Priority: " + 
				myMessage.Priority.ToString());
	
			return;
			}
	}
}

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

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)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft