Exporting Custom Metadata for a WCF Extension
In Windows Communication Foundation (WCF), metadata export is the process of describing service endpoints and projecting them into a parallel, standardized representation that clients can use to understand how to use the service. Custom metadata consists of XML elements that the system-provided metadata exporters cannot export. Typically, this includes custom WSDL elements for user-defined behaviors and binding elements and policy assertions about the capabilities and requirements of bindings and contracts.
This section describes exporting custom WSDL or policy assertions, and does not focus on the exporting process itself. For more information about how to use the types that export and import metadata regardless of whether the metadata is custom or system-constructed, see Exporting and Importing Metadata.
Overview
When metadata is published using the System.ServiceModel.Description.ServiceMetadataBehavior, the System.ServiceModel.Description.ServiceDescription is examined and XSD and WSDL -- including policy assertions -- are generated for all contracts and bindings that WCF can support using system-provided attributes and bindings. However, custom behavior attributes or binding elements require support before they can be exported properly.
This section describes:
How to implement and use the System.ServiceModel.Description.IWsdlExportExtension interface, which exposes the WSDL generation data to you prior to publishing the WSDL.
How to implement and use the System.ServiceModel.Description.IPolicyExportExtension interface, which exposes the policy data to you prior to exporting the policy assertions in WSDL data.
For more information about importing custom WSDL and policy assertions, see Importing Custom Metadata for a WCF Extension.
Exporting Custom WSDL Elements
Implement the IWsdlExportExtension on an operation behavior, contract behavior, endpoint behavior or binding element (IOperationBehavior, IContractBehavior, IEndpointBehavior, or System.ServiceModel.Channels.BindingElement respectively) and insert the behaviors or binding elements into the description of the service that you are trying to export. (For more information about inserting behaviors, see Configuring and Extending the Runtime with Behaviors). The IWsdlExportExtension is called for each endpoint and each endpoint exports the contract first if it has not already been exported. You can participate in either export process, depending upon your needs:
Use the WsdlContractConversionContext to modify the exported metadata in the ExportContract method.
Use the WsdlEndpointConversionContext to modify the exported metadata for the endpoint in the ExportEndpoint method.
The ExportContract method is called on all IWsdlExportExtension implementations within the System.ServiceModel.Description.ContractDescription instance that is being exported. The ExportEndpoint method is called on all IWsdlExportExtension implementations with the System.ServiceModel.Description.ServiceEndpoint instance that is being exported.
For more information, see How to: Export Custom WSDL and the sample Custom WSDL Publication.
Exporting Custom Policy Assertions
Implement the IPolicyExportExtension on a BindingElement and add the binding element to the binding to write custom policy assertions about binding support and contract capabilities into the WSDL. The IPolicyExportExtension is called once when exporting the implemented binding element in a binding and passes the PolicyConversionContext to the ExportPolicy method. You can use the methods on the PolicyConversionContext instance to add to the policy assertions attached to the WSDL binding at the message, operation or endpoint subjects.
For more information, see How to: Export Custom Policy Assertions.
See Also
Tasks
How to: Export Custom WSDL
How to: Export Custom Policy Assertions