MessageQuery Class

.NET Framework (current version)

Defines the core behavior of classes used to search for specific correlating data in a message.

Namespace:   System.ServiceModel.Dispatcher
Assembly:  System.ServiceModel (in System.ServiceModel.dll)


public ref class MessageQuery abstract 


Initializes a new instance of the MessageQuery class.


Creates a collection of queries that returns a specific type of data associated with it.


Determines whether the specified object is equal to the current object.(Inherited from Object.)


When overridden in a derived class, runs a query against the message and returns a result. The body cannot be queried.


When overridden in a derived class, runs a query against the message and returns a result.


Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)


Serves as the default hash function. (Inherited from Object.)


Gets the Type of the current instance.(Inherited from Object.)


Creates a shallow copy of the current Object.(Inherited from Object.)


Returns a string that represents the current object.(Inherited from Object.)

The MessageQuery class is similar to the MessageFilter class. However, instead of returning matches, the Evaluate method returns the results of evaluating a query against a message. The result of the query is a value in the message. Use the value as a key to correlate the message to other messages. To add a new property for the data, use the Add method of the CorrelationDataMessageProperty class.


For a concrete implementation of the MessageQuery, see the XPathMessageQuery class.

You can optimize the query process by creating a set of query objects and inserting them into an instance of the MessageQueryCollection class.


For a concrete implementation of the MessageQueryCollection, see the XPathMessageQueryCollection class.

A common usage is to populate the collection with queries that have the same XPath predicate, but that differ only in the final leaf value. For example, the following XPath queries are identical except for the final clause. The first queries for all elements that have the quantity attribute set to 1, and the second queries for elements with the product attribute set to 'Contoso'):

"/s12:Envelope/s12:Body/PurchaseOrder/Items/Item[@quantity = 1]"
"/s12:Envelope/s12:Body/PurchaseOrder/Items/Item[@product = 'Contoso']"

The MessageQueryCollection class allows you to create tables of queries that differ only slightly, enabling more efficient processing.

Alternatively, you can use the MessageQueryTable<TItem> class to store and evaluate message queries.

The following example creates a message and XPath message queries. The queries are evaluated by the XPathMessageQuery objects contained in an XPathMessageQueryCollection object. The results of each query are tested using the ResultType property of the XPathResult class.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 4.0

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top