Through the introduction of the matching relationship between the three elements of the WSDL element and the endpoint, we know that the Binding element of the WSDL element comes from the Binding object of the endpoint, so how are these Binding-based Metadata and corresponding policy assertions written into the WSDL?WSDL Export Extension (WSDL Export Extension)AndPolicy Export Extension)It is designed for this purpose.
1. WSDL Export Extension)
The binding of an endpoint is essentially an ordered combination of related bindingelements (for in-depth analysis of binding, refer to Chapter 3rd of WCF Technology Analysis (Volume 1 ), therefore, the binding-based WSDL export extension is implemented by binding elements. The System. ServiceModel. Description. IWsdlExportExtension interface must be implemented for Binding elements that need to be added to the exported WSDL for Binding-related metadata.
In addition, the WSDL export extension is not limited to adding Binding-related metadata by the corresponding Binding element, we can also use the endpoint behavior, contract behavior, and operation behavior (service behavior cannot be used for WSDL export extension) as the WSDL export extension to add custom metadata to the final generated WSDL. The IWsdlExportExtension interface must be implemented as the preceding three actions of the WSDL export extension.
The following code snippet defines the IWsdlExportExtension interface, which defines two methods: ExportContract and ExportEndpoint, which correspond to methods with the same name of WsdlExporter respectively.
1: public interface IWsdlExportExtension
2: {
3: void ExportContract(WsdlExporter exporter, WsdlContractConversionContext context);
4: void ExportEndpoint(WsdlExporter exporter, WsdlEndpointConversionContext context);
5: }
From the definition of WsdlExporter, we know that whether the ExportContract or ExportEndpoint method is called, the exported metadata is not directly returned. The exported metadata is obtained through GetGeneratedMetadata in another additional method. In fact, when you call the ExportContract or ExportEndpoint method of WsdlExporter, the exported metadata is saved to a Context based on the WsdlExporter object. For the ExportContract method, the context object is WsdlContractConversionContext, And the ExportEndpoint method is WsdlEndpointConversionContext.
At the final stage of executing the ExportContract or ExportEndpoint method, all the WSDL export extension elements that implement the IWsdlExportExtension interface will be traversed (for the ExportContract method, that is, all three behavior objects that implement the IWsdlExportExtension interface; for the ExportEndpoint method, including the behavior object and binding element that implements the IWsdlExportExtension Interface), and The WsdlExporter object itself and the corresponding context object (WsdlContractConversionContext or WsdlEndpointConversionContext) execute the extended ExportContract method or ExportEndpoint method as a parameter to export the WSDL, and finally write the customized metadata into the final WSDL.
The WSDL export extension does not include the export of WS-Policy assertions. This implementation is defined in another export extension, that is, Policy Export extension.
Ii. Policy Export Extension)
In Chapter 3rd of WCF Technology Analysis (Volume 1), we said that most WS specifications are ultimately implemented through binding, or, WCF provides support for a WS specification by defining corresponding binding elements. Therefore, the end point binding includes a lot of WS-Policy Assertions based on the corresponding WS specifications that need to be exported as metadata to the final generated WSDL. For example, for WSHttpBinding, if the message-based Security mode is adopted, the WS-Security-related policy assertions need to be exported; how can we enable the Reliable Session ), policy Assertions based on the WS-RM (WS-Reliable Messaging) need to be exported. In the WCF metadata structure, Policy Export extension is used to export WS-Policy assertions.
All binding elements that need to be exported using WS-Policy assertions must implement the System. ServiceModel. Description. IPolicyExportExtension interface. The IPolicyExportExtension interface only defines the following method Member: ExportPolicy.
1: public interface IPolicyExportExtension
2: {
3: void ExportPolicy(MetadataExporter exporter, PolicyConversionContext context);
4: }
When WsdlExporter executes the final stage of the ExportEndpoint method, the PolicyConversionContext object is created. Traverse all the binding elements that implement the IPolicyExportExtension interface, and call the ExportPolicy method of these binding elements by using the WsdlExporter object and the PolicyConversionContext object as parameters. These binding elements used as Policy Export extensions export the corresponding WS-Policy-based metadata to the PolicyConversionContext object. After all the binding elements are executed, attach the policy metadata temporarily stored in PolicyConversionContext to the WsdlEndpointConversionContext object mentioned above, the exported metadata contains the corresponding WS-Policy assertions.
Author: Artech
Source: http://artech.cnblogs.com
The copyright of this article is shared by the author and the blog Park. You are welcome to repost this article. However, you must retain this statement without the author's consent and provide a clear link to the original article on the article page. Otherwise, you will be held legally liable.