I. Summary
1. wse1.0 SP1
WSe (Web Services enhancements) is a tool provided by Microsoft to implement WS-Security, WS-routing,
WS-Attachments and dime
And other standard components (DLL ). This allows developers to develop corresponding web services without having to have a deep understanding of the specific content of the above protocols.
Program, greatly simplifying the development difficulty, making web services applications possible in enterprise-level projects.
2. Common usage
Add/modify custom SOAP Headers
▲Add Authentication
▲Encrypt soapbody Information
▲Attachments used
Add soap Router Information
Ii. Design
2.1 proposal of the project:
In an online procurement system, each supplier provides a Web service to the purchaser, with a webmethod that provides the goods list. The name of this webmethod
Words can be different, but they all provide the same interface. Here, we assume that two entry parameters are required, and a string is returned.
Type XML file. As to why two parameters are required, we will introduce them later in this article. In actual implementation, the interface can formulate the corresponding specifications, so that the proxy can be reused to the maximum extent.
.
A purchaser hopes to obtain the best procurement solution (this article only discusses the technical level, interpersonal relationship, company relationship, etc., and does not do research), then it will join as many suppliers as possible. It is possible that
There will be new suppliers in every day, so the buyer system must be a scalable system. In this example, when the purchaser needs to query the supply information of a part, it will use
Getallproduct (string
Name) to call all WebServices and display the returned results. This article focuses only on WSE, so we will not discuss more about system design issues. Because
This project was created on a temporary basis, so it is not perfect in many aspects. However, I only describe how WSE is used and it is a purely technical discussion.
Because a new WebService is added at any time, if we add a web reference to the Web
Services, the program is very dead, without flexibility and scalability. Therefore, we need the program to generate a proxy Based on the WSDL of WebServices and compile it
The corresponding DLL. Here, we can manually define a serviceid as the primary key to uniquely specify a WebServices. In actual development, we will use
Proxy and factory design patterns are used to design the system. The proxy generation and proxy construction of different wdsl are encapsulated into relatively independent modules. We will use
Wsdl.exe application and. Net reflecting (reflection.
When calling WebService or receiving returned information, we may need to add some additional operations, such as identity authentication, customized soapheader, and encryption. Here I will
Use wse1.0 provided by Microsoft. For details about how to implement Quick Start, refer to the Quick Start example provided by Microsoft. It is included in the wse1.0sp1 download package. The specific location is as follows:
Http://www.microsoft.com/downloads/details.aspx? Familyid = 06255a94-2635-4d29-a90c-28b282993a41 & displaylang = en
2.2 proxy generation and use
1. automatically generate a proxy File Based on WSDL (prxoyfactory, using WSDL. EXE)
You can create a tool to generate a proxy CS File Based on the provided WSDL address. The main code is as follows:
String parameter = wsdlurl;
Parameter + = "/L: C #";
Parameter + = "/N:" + serviceid;
Parameter + = "/O:" + constants. LIBRARY_PATH + "//" + serviceid + ". cs ";
// Use serviceid as output file name
Try
{
Processstartinfo startinfo = new processstartinfo (constants. wsdl_path, parameter );
[Next Page]
Process = process. Start (startinfo );
Process. waitforexit ();
If (process. exitcode! = 0)
Throw new exception ("generate proxy error ");
Return true;
}
Catch (exception ex)
{
}
Example 2.1
2. Modify and generate the proxy file, and change the original inheritance httpwebclientprotocol to Microsoft. Web. Services. webservicesclientprotocol.
3. Add different pipeline (pipelinefactory) for different proxies based on the database content)
Each proxy has a default Pipeline provided by Microsoft. This pipeline includes
Outputfilter, inputfilter, and all the filter order is crucial. Therefore, we are designing a WebServices
A unique serviceid is specified and the filter to be used is added to the table corresponding to the database. The table should have the filte type (I/O), sequence, and name.
. :
4. In proxy, the invoke WebService method should be different based on different webmethod names.
As follows:
Object [] Results = This. Invoke (pipeline. operationname, new object [] {
Msgid,
Sxml });
5. If you want
Filter is added to WebService. Currently, it can only be added to application_start () of the Global. asax file. Therefore, if
WebService provides multiple webmethods, and different filters (or none) may be required for different webmethods ). In this case,
Webmethods can be separated to form multiple WebServices. The filter in each global. asaz only applies to the visual
The folder request/response takes effect.
6. Note that if we need
Add filter to the server to provide decryption and verification functions. We have two options. One is in the global. asax File
Application_start () is added to all filters, and the other is added to Web. config. In this way, all SOAP requests to this virtual directory will
Filter. However, if this WebServices provides two webmethods and only one of them needs filter, and the other does not
The method cannot be implemented. I still want to know how to dynamically allocate filters for each SOAP request (similar to the proxy request end). Anyone who knows can tell me, thank you.
Thank you.