Share via


Creating Custom Filters with WSE

The outgoing and incoming filters that are built into WSE provide functionality for diagnostic, security, time stamp, referral, and routing features. WSE also makes it possible to deploy user-defined custom filters on incoming or outgoing messages. These custom filters can use any information contained in a SOAP message to determine how to process the message. For example, a filter can be set to process messages from a particular set of senders differently than other messages are processed. Multiple customized filters can be applied to either incoming or outgoing messages, allowing considerable flexibility with the processing logic.

WSE places filters in a pipeline, represented by the Pipeline class. This class contains two properties that are collections of filters. The OutputFilters property returns a collection of filters that can be applied to any outgoing message. Similarly, the InputFilters property returns a collection of filters that can be applied to any incoming message.

Filters communicate with user code through the SoapContext class, which contains a series of properties as well as a hash table. Typically, user code for outgoing or incoming messages passes the data between the hash table and the filters.

WSE makes it possible to place the custom input and output filters in positions other than their default positions by specifying exactly where they should be inserted in the pipeline relative to the other filters. For example, you could remove the standard referral filter and insert a custom referral filter in the same position in the pipeline that the standard one had been. For more information, see How to: Create and Add a Custom Input Filter.

Adding Custom Input and Output Filters to the Pipeline

WSE also allows you to create your own custom filters for processing or modifying incoming and outgoing messages.

To create a custom filter that modifies an outgoing message, create a class that derives from the SoapOutputFilter class. The filter must implement the ProcessMessage method, which takes the outgoing message as a parameter of type SoapEnvelope. Further, the SoapEnvelope class contains a Context property that returns a SoapContext object. When processing a message with a custom filter, the SoapEnvelope can be modified by setting properties of the SoapContext. When you have created a collection of output filters, you can add each custom filter to the collection of output filters returned by the OutputFilters property of the Pipeline.

Conversely, you can create custom filters that modify incoming messages by creating classes that derive from the SoapInputFilter class and adding the input filters to the collection of input filters returned by the InputFilters property of the Pipeline.

Note

Users who want to process a mustUnderstand header should use a custom input filter and not content-based routing. The mustUnderstand fault checking is done before the ProcessRequestMessage method is called, so attempting to use content-based routing will always result in a mustUnderstand fault at the client.

See Also

Tasks

How to: Create and Add a Custom Output Filter
How to: Create and Add a Custom Input Filter

Concepts

Filters Included with WSE