WCF Technical Profiling 26: How to export the metadata for a WCF service (Metadata) [Extended articles]

Source: Internet
Author: User
Tags final object object wsdl

By introducing the matching relationship between the WSDL element and the three elements of the endpoint through the implementation chapter, we know that the binding element of the WSDL originates from the binding object of the endpoint, so how are the binding metadata and the corresponding policy assertions written to the WSDL? The WSDL Export Extension (WSDL exports Extension) and the Policy export extension (Policy export Extension) are designed for this purpose.

First, WSDL Export extension (WSDL exports Extension)

The binding of an endpoint is essentially an ordered combination of related binding elements (BindingElement) (an in-depth analysis of bindings, which can be referenced in chapter 3rd of WCF Profiling (Volume 1)), so the WSDL export extension based on bindings is implemented as a binding element. The System.ServiceModel.Description.IWsdlExportExtension interface must be implemented for binding elements that need to be added to the binding related metadata to the final exported WSDL.

In addition, the WSDL export extension is not limited to being used by the corresponding binding element to add binding related metadata, we can also use endpoint behavior, Contractual behavior and operational behavior (service behavior cannot be used for WSDL export extensions) as a WSDL export extension implementation adds custom metadata to the resulting WSDL. The above three behaviors, which are exported as WSDL, also need to implement the Iwsdlexportextension interface.

The following code fragment gives the definition of the Iwsdlexportextension interface, which defines two methods: Exportcontract and Exportendpoint, respectively, corresponding to Wsdlexporter's method of the same name.

   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 neither the call to Exportcontract or the Exportendpoint method will return the exported metadata directly, The final exported metadata is obtained by Getgeneratedmetadata in another additional method. In fact, when the Wsdlexporter exportcontract or Exportendpoint method is invoked, the exported metadata is temporarily stored in a context (in contexts) based on the Wsdlexporter object. For the Exportcontract method, this context object is wsdlcontractconversioncontext and for the Exportendpoint method is Wsdlendpointconversioncontext.

In the final phase of executing the Exportcontract or Exportendpoint method, all WSDL export extension elements that implement the Iwsdlexportextension interface are traversed (for the Exportcontract method, That is, all 3 kinds of behavioral objects that implement the Iwsdlexportextension interface, and for Exportendpoint methods, including the behavior objects and binding elements that implement the Iwsdlexportextension interface, The Wsdlexporter object itself and the corresponding context object (Wsdlcontractconversioncontext or wsdlendpointconversioncontext) are executed as parameters by the WSDL export extension Exportcontract method or The Exportendpoint method ultimately implements the purpose of writing the custom metadata to the final WSDL.

The WSDL export extension does not contain an export of the Ws-policy policy assertion, which is defined in another export extension, the policy export extension.

Second, Policy export extension (Policy export Extension)

In the introduction to bindings in the 3rd chapter of WCF Profiling (Volume 1), we say that most WS specifications are ultimately implemented through binding, or that WCF supports a WS specification by defining the appropriate binding elements. Therefore, the binding of endpoints contains many Ws-policy policy assertions based on the appropriate WS specification that need to be exported as metadata to the resulting WSDL. For example, for Wshttpbinding, if you adopt a message-based security model, you need to export policy assertions based on ws-security, how to turn on a reliable session (reliable sessions), and export based on WS-RM (ws-reliable Messaging) related policy assertions. In the WCF metadata structure system, the export of the Ws-policy policy assertion is realized through the policy export extension.

All binding elements that need to implement the Ws-policy policy assertion export must implement the System.ServiceModel.Description.IPolicyExportExtension interface. The Ipolicyexportextension interface defines only one of the following method members: Exportpolicy.

   1:public Interface Ipolicyexportextension
2: {
3: void Exportpolicy (metadataexporter exporter, policyconversioncontext context);
4:}

The Policyconversioncontext object is created when Wsdlexporter executes the final phase of the Exportendpoint method. Iterate through all the binding elements that implement the Ipolicyexportextension interface, The Exportpolicy method of these binding elements is called with the Wsdlexporter object itself and the Policyconversioncontext object object as arguments. These binding elements that export extensions as policies export the corresponding metadata based on the Ws-policy policy to the Policyconversioncontext object. After all the binding elements have been executed, the policy metadata that is staged in Policyconversioncontext is appended to the Wsdlendpointconversioncontext object mentioned above. Then the last exported metadata contains the corresponding Ws-policy policy assertion.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.