Declarative WSE pipeline configuration
Note: this entry has moved.
Configuring the WSE pipeline (1.x) is explained in the Configure a Custom Filter section in an MSDN article that also explains how to manipulate programatically the pipeline. The configuration, however, only allows ADDING a filter, not removing or changing the filters execution order or position. In this post I will explain how to achieve what I explained at the end of a previous post, that is, have complete declarative control over WSE pipeline configuration.
Basically, what I wanted is to have a configuration file as follows:
And have WSE pipeline configured accordingly. In a web
application, I would have to force the appropriate config.
handler to run at the Application_Start event
by issuing one of the following:
FilterConfiguration filters = (FilterConfiguration)
ConfigurationSettings.GetConfig(WseConfiguration.SectionName);
//Or
WseConfiguration.Initialize();
This involves creating a section handler and processing each
of the elements in the <filters> node.
The method that is called with the handler is created looks
as follows:
I'm caching the expression that locates the filters so improve performance, and to make the code more maintainable. I keep all element and attribute names in constants:
Of course, the real work happens in AddFilter,
RemoveFilter and MoveFilter. As
WSE has a clear distiction between input and output filters
by means of different base classes for them,
SoapInputFilter and
SoapOutputFilter, we don't need to bother to
specify which kind of filter we're adding/removing/moving,
and we can instead infer this in those helper methods. These
methods use the approach explained in the aforementioned
MSDN article
to pipeline handling. Here's the AddFilter one:
Note that we insert or add depending on the presence of the
@at attribute. The RemoveFilter does almost
the same, so I won't show the full code. The move filter is
slightly more complicated as we can only move around filters
that already exist on the pipeline. Fortunately the
SoapInputFilterCollection (and the output too)
class exposes an IndexOf method that receives
the filter type to locate, which comes handy now:
I've provided this code as a C# project in the
ASPNET2 Incubator
(work-in-progress still), and you can download it
from here.
I also included the two signature filters discussed in the
aforementioned post
for reducing WSE message payload by avoiding sending the
binary security token when it is agreed and distributed
previously between secured parties/servers. Look for the
SecurityTokenHelper.cs file. Its static
constructor should load the SecurityToken you
will use to secure communication.