Supplement on the Summary of WSE
With the progress of the project, there is more understanding of WSE, and a few days ago suddenly think of a way to dynamically joined Filter in Server. Personally think this is feasible, and quickly take it out and share it.
In the WSE summary, I didn't have the service request for service requests for the entire site in the WSE. It is actually incorrect. For example, we can inherit httpmoudle to process all entered HTTP requests, and Microsoft websites have related examples. Just starting at the actual situation, in the case I said, our custom FILTER is actually associated with a serviceID in SOAP. That is, different serviceid corresponds to different filters. If we write the corresponding HTTP handlers without using the function provided by WSE, it is undoubtedly a fee-cost. However, these filters can only be added in Global.asax, then how should we deal with?
There is a variant method to solve the above problems well. That is to combine custom Filter with global.asax. For the convenience of me, I have a total of 4 custom Filter, they are,
,
first name
use
InputHeaderfilter
Verify that SOAP Header complies with SCHEMA
InputAafilter
encryption
OutputHeaderfilter
Join OAP Header Information
OutputAafilter
Decrypt
OutputAllFilter
Processing SOAP information (conversion)
Assuming serviceID = "001" user request only needs to pass throughaafilter, and only OutputAafter will only be passed when the server returns. However, the user request of serviceid = "002" may need to pass through the above four filters. Then we cannot join the Filter in Global.asax or Web.config files. Filter and filter order of different serviceids may be different, so we need to dynamically add these filters and execute.
INPUTFILTER
First, we can make this so, we can get a serviceID in Web Method and create a new PIPELINE object and join all filters in a certain order (the database has the corresponding field representation order), then use the pipeline's iProcessInputMessage () method to complete The operation of Input Filter should be performed in the design, the code is as follows:
// Input filter
PIPELINE ReplyPip = new pipeline ();
// Add a Filter
/ / In order to facilitate explanation, it is not used to add from the database read.
// Need to pay attention to the order of adding the future cannot be reversed!
Replypip.inputfilters.add (New aainboundfilter ());
// Perform all InputFilter
ReplyPip.ProcessInputMessage (RequestContext.envelop);
In this way, we have completed the function of the server-end InputFilter, and the code will be called in WebMethod.
Outputfilter's processing
For OutputFilter's situation, it is more complicated because if we use the technical processing of the above technology to process outputfilter (ResponseContext.Envelope) due to ResponseContext.Envelope is Readonly, we cannot create and modify this property in the program, so I will use a substitute conversion. Method is realized. First, create a new SOAPENVELOPE object, then use technologies similar to the InputFilter to add Outfilter and process it, get the SOAPENVELOPE that is consistent with the real-needed Response Sope information. Then save this SOAPENVELOPE to the RESPONSECONTEXT, then remove it in the OutputAllFilter, and assign the SOAP information returned by the server. The entire code is as follows: WebMethod:
// Add Output Filter
Replypip.outputfilters.add (new aaoutboundfilter ());
SOAPENVELOPE ENV = New sopeNvelope ();
// Process Output Soapenvelope
// The envelope here is not real return information, just avatars
// Users can control which Output filters can be used
ReplyPip.ProcessOutputMessage (ENV);
/ / Save the modified simulated envelope information in the responseContext object
HTTPSOAPCONTEXT.RESPONSECONTEXT.ADD ("ENV", ENV);
Add the following code in Global.asax Application_Start () Add the following code:
WebservicesConfiguration.filterConfiguration.outputFilters.Add
New outputAllFilter ());
This way, all responding SOAP information of this site will pass this OUTFILTER.
Finally, the OutputAllFilter.cs is as follows:
Using system;
USING SYSTEM.XML;
USING Microsoft.Web.Services;
USING SYSTEM.XML.SCHEMA;
Using system.collections;
Namespace RottenApple
{
Public Class OutputAllFilter: SOAPOUTPUTFILTER
{
Public OutputAllFilter ()
{
//
// Todo: add constructor logic here
//
}
Public Override Void ProcessMessage (SOAPENVELOPE ENVELOPE)
{
// If the env is Object, do not perform the conversion
// This filter will be executed when calling the pipeline / processoutfilter, but at that time
// Don't do anything
Envelope.Context.Contains ("ENV")))
{
SOAPENVELOPE ENV = (SOAPENVELOPE) Envelope.Context ["ENV"];
XMLNode header = envelope.header;
IF (header == null)
Header = envelope.createHeader ();
Header.innerxml = env.Header.innerXML;
}
}
}
}
The above code is passed under VS2003, WSE1.0SP1.