Web Services Enhancements 1.0 for Microsoft .NET works; Independent filter and filter pipeline work principle; configuration default pipeline method; method for creating custom filters; DIME is fit in the picture.
Download Web Services Enhancements 1.0 for Microsoft .NET (English). Introduction
Web Services Enhancements 1.0 for Microsoft .NET (WSE) is a class library for advanced Web service protocols. The WSE architecture model is based on the filter pipeline that handles the inbound and outbound SOAP messages. The filter can be integrated with the ASP.NET Web service infrastructure, or it can be used separately. Introduce the working principle of WSE pipe technology, introducing the working principle of individual filters and filter pipelines, configuring the default pipeline method, and the method of creating custom filters and DIME fitting features.
Filter-centric model
WSE is an engine that applies advanced Web service protocols to the SOAP message. It requires the header to the header, read the header from the inbound SOAP message; it also requires the conversion of the SOAP message body. For example, encrypting the outbound message body and decryption inbound message body as defined in the WS-SECURITY specification. In WSE, this feature is implemented by a filter. The output filter writes the header to the message, the filter reads the header from the message and check the validity of the header. Further output and input filters can convert the contents of the message. Figure 1 illustrates a WSE filter model.
Figure 1: Filter model for Web Services Enhancements
Use a separate filter
Understanding how WSE uses filters to start from a simple example. WSE provides a pair of filters for reading and writing timestamp headers. The timestamp header contains some elements, used to represent the creation time and expiration time of the message, indicating the period of the message, and when it can be considered to be invalid. The timestamp filter is defined in the Microsoft.Web.Services.TimeStamp namespace. As the name suggests, TimeStampOutputFilter is an output filter that writes the timestamp header to the SOAP message; and the TimeStampInputFilter is an input filter for reading the timestamp header from the SOAP message. The following is their respective definitions:
public class TimestampOutputFilter: SoapOutputFilter {public override void ProcessMessage (SoapEnvelope envelope);} public class TimestampInputFilter: SoapInputFilter {public override void ProcessMessage (SoapEnvelope envelope);}
Both classes have a ProcessMessage method, which has a parameter of a SOAPENVELOPE type. Microsoft.Web.Services.soApenvelope class is the extension of standard .NET XML DOM API System.xml.xmldocument. It has verification logic, which can verify document content that contains a valid SOAP message; it also has some shortcuts and properties, which can create and access specific parts of the message, that is, Envelope, Header, and Body elements.
The following is a simple application using a timestamp filter.
Static void main (String [] args) {// Create a blank SOAP message soapenvelope env = new soplace (); xmlelement body = env.createbody (); env.Envelope.Appendchild (body); // Print the original message console. WriteLine ("Raw Message: / N / N {0} / N", Env.outerXML); // Create Timestamp Output Filter TimeStampoutputFilter Tsoutput = New TimeStampOutputFilter (); // Processing Message, Write Time Pamp Head Tsoutput .ProcessMessage (ENV); // Print the output filtered message console.writeLine ("Message after the output filter: / n / n {0} / n", env.outerxml); // Create a timestamp input filter TimeStampinputFilter Tsinput = new timestampinputfilter (); // Processing message, read timestamp head tsinput.processMessage (env); // Print input filtered message console.writeLine ("Enter the filtered message: / n / n {0} / n ", env.outerxml;} This program first creates a SOAPENVELOPE object and adds a blank message body. Then, create a TimeStampOutputFilter and use it to handle SOAPENVELOPE, write to the message to the timestamp head. Finally, the program creates a TimeStampInputFilter and uses it to handle SOAPENVELOPE, read the timestamp header from the message. Each step of the program execution prints the message content to the console. The following is the output result (already arranged in format).
Original message:
Output filtered message:
The output filter is managed by Microsoft.Web.Services.SoAppContext class. Each SOAPCONText object uses a simple object model to record specific protocol options, such as whether there is a username tag or digital certificate, create and expire timestamp, routing path, etc. The SOAPENVELOPE class has a context property that is an instance of the SOAPCONText class. When SOAPENVELOPE is processed by the output filter, it is the data in the SOAPContext object tells the output filter.
For example, TimeStampOutputFilter actually sets the expiration time of the message by checking the properties of the SOAPENVELOPE's SOAPCONText object (especially soapenvelope.context.timestamps.ttl). If you want to set the expiration time of the message to 10 minutes, you only need to set this value according to the following:
// Create a package soapenvelope env = new soapenvelope (); ... // set in milliseconds, set the expiration time to 10 minutes env.context.TimeStamps.ttl = 600000;
The WSE input filter also depends on the SOAPCONText class, but its use is different. When the filter is input to the SOAPENVELOPE object, its SOAPCONTEXT object is updated to reflect the package contained in the protocol header. For example, after the TimeStampInputFilter processes the message, the soapenvelope.context.timestamps.created property reflects the creation time of the message.
Use multiple filters in the pipeline
The timestamp input and output filters previously displayed are only two of the 10 built-in filters belled in WSE. Table 1 lists all built-in filters, including their namespace, input, and output filters type names, and simple features.
Table 1: WSE built-in filter in Web Services Enhancements
Namespace input filter output filter uses Microsoft.Web.Services.DiagnosticsTraceInputFilterTraceOutputFilter write information to the log file to help debug Microsoft.Web.Services.SecuritySecurityInputFilterSecurityOutputFilter authentication, signing and encryption support (WS-Security (English)) Microsoft. Web.Services.TimestampTimestampInputFilterTimestampOutputFilter stamping support (WS-Security (English)) Microsoft.Web.Services.ReferralReferralInputFilterReferralOutputFilter dynamically updated routing path (WS-Referral (English)) Microsoft.Web.Services.RoutingRoutingInputFilterRoutingOutputFilter message routing (WS-routing (English )) The rightmost column in Table 1 clearly illustrates the function of each pair of WSE filters. In general, you may want to combine multiple inputs or output filters to apply to a given SOAP message EN MASSE. To this end, WSE provides Microsoft.Web.Services.Pipeline class, which is defined below.
public class Pipeline {public Pipeline (); public Pipeline (Pipeline p); public Pipeline (SoapInputFilterCollection inputFilters, SoapOutputFilterCollection outputFilters); public SoapInputFilterCollection inputFilters {get;} public SoapOutputFilterCollection outputFilters {get;} public void ProcessInputMessage (SoapEnvelope envelope); public void ProcessOutputMessage (SOAPENVELOPE Envelope);
Each PIPELINE object encapsulates an input filter collection and an output filter collection, which is represented by Microsoft.Web.Services.soapInputFilterCollection and Microsoft.Web.Services.soapoutPutFilterCollection class instance. These sets are initialized by a constructor and is provided as an attribute. Pipeline.ProcessInputMessage and PipeLine.ProcessOutputMessage methods perform simple iterations in the corresponding filter collection, sequentially pass the supplied SOAPENVELOPE objects.
Below is a simple program using the PIPELINE class, which uses multiple output filters to process messages. In particular, the TraceOutputFilter and TimeStampOutputFilter class built in WSE are used.
static void Main (string [] args) {// Create a set of input filters SoapInputFilterCollection inputFilters = new SoapInputFilterCollection (); // create output filter set SoapOutputFilterCollection outputFilters = new SoapOutputFilterCollection (); // add the desired filter output outputFilters .Add (new TraceOutputFilter ()); outputFilters.Add (new TimestampOutputFilter ()); // create an empty SOAP message SoapEnvelope env = new SoapEnvelope (); XmlElement body = env.CreateBody (); env.Envelope.AppendChild (body ); // Print the original message console.writeline ("Raw Message: / N / N {0} / N", Env.outerXML); // Create a pipe, package filter set PipeLine Pipe = new pipeline (InputFilters, OutputFilters) ; // Use all output filter // processing messages in the collection of pipes Pipe.ProcessOutputMessage (ENV); // Print the output filtered message console.writeLine ("Output filtered message: / n / n {0} / n ", env.outerxml;} This application first creates an empty SOAPINPUTFILTERCOLLECTION object. Then create a SOAPOUTPUTFILTERCOLLECTION object and add a TraceOutputFilter object and a TimeStampOutputFilter object. Then use these two collections to initialize a new PIPELINE object. Then use Pipeline to handle empty soapenvelope. The output of the program is as follows.
Original message:
Output filtered message:
Figure 2: Filter processing order in the Pipeline class The Pipeline class has a sufficient reason to use this way of work. If the input and output filter sets move in the same order, you must manually reverse a set of filters in the code. The PIPELINE class is liberated by using an inverse sequence processing in ProcessOutputMessage. You can "add" corresponding "input and output filters to its respective collections, and leave the remaining work to Pipeline. Default pipeline In most applications, you are likely to want the PIPELINE object to use the same input and output filters. To do this, WSE supports the default pipeline configuration. Microsoft.Web.Services.Configuration.WebservicesConfiguration class provides a static filterconfiguration property that maintains a pair of filter collections, which are provided via the inputfilters and OutputFilters properties. When using the default constructor to instantiate the PIPELINE class, the reference to the default filter is copied to the filter collection of the new object. You can modify the default Pipeline configuration for each appdomain. Use the built-in WSE filter to pre-configure the default input and output filter collection. Table 2 shows these configurations. Table 2: Pre-configured default pipeline configuration Index Enter Filter Output Filter 0securityInputFilterSecurityOutputFilter1TimeStampinputFilTerTimeStampoutputFilter2ReferRalInputFilterReferRaloutputFilter3RoutingInputFilterRoutingOutputFilterRoutingoutputFilter Note that the index smaller filter is more "close to the line", and the indexed filter is more "close to code". If the trace function is enabled in WSE, TraceInputFilter and TraceOutputFilter will be inserted to the front, namely 0 positions to the default filter collection. This is very meaningful because the target of tracking the filter is to record the message access line. If you prefer, you can modify the default filter collection of AppDomain. For example, if you wish that the application uses WS-Security instead of WS-Routing and WS-REFERRAL, you can delete the route and referred to the filter. In general, deleting unwanted filters can reduce the number of objects that must check each SOAP message, thereby increasing the performance of the application. The following methods explain how to remove routing and reference headers from the default input and output filters. public static void ReconfigureDefaultPipeline () {// retrieve the default input filter set SoapInputFilterCollection defaultInputFilters = WebServicesConfiguration.FilterConfiguration.InputFilters; // delete routes and the reference input filter defaultInputFilters.Remove (typeof (RoutingInputFilter)); defaultInputFilters.Remove (typeof ( ReferralInputFilter)); // retrieve the default output filter set SoapOutputFilterCollection defaultOutputFilters = WebServicesConfiguration.FilterConfiguraiton.OutputFilters; // delete routes and the reference filter output defaultOutputFilters.Remove (typeof (RoutingOutputFilter)); defaultOutputFilters.Remove (typeof (ReferralOutputFilter)) } It is worth noting that modifying the default filter set has no impact on existing PipeLine objects. Only the new PIPELINE object created after changing the default collection will be affected by this modification. For example, in the following code, two PIPELINE objects use different filters. Static void main (String [] args) {// The first pipe has all filters PipeLine Pipe1 = new pipeline (); // Modify the default filter collection, // Remove the route and refer to filter reconfiguredefaultPipeLine (); / / The second pipe has a safety and // timestamp filter, but does not have // routes and reference filters pipeline pipe2 = new pipeline (); ... // use pipeline} If you use a WSE and ASP.NET Web services, you can use the Global.asax file to modify the default filter collection when the service is started at the application. Here is an example: <% @ Import namespace = "Microsoft.Web.Services"%> <% @ Import namespace = "microsoft.web.services.configuration"%> <% @ import namespace = "microsoft.web.services.Routing"%> < % @ import namespace = "Microsoft.Web.Services.Referral"%>