IPolicyImportExtension Interface


Defines a method for objects that import custom policy assertions about bindings.

Namespace:   System.ServiceModel.Description
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

type IPolicyImportExtension = interface end

System_CAPS_pubmethodImportPolicy(MetadataImporter, PolicyConversionContext)

Defines a method that can import custom policy assertions and add implementing binding elements.

Implement the IPolicyImportExtension interface to search WSDL information exposed by a particular endpoint for custom policy assertions about endpoint capabilities or requirements. Typically, a policy importer searches for a specific assertion and either inserts a binding element, configures a binding element, or modifies the contract to support the requirements of the assertion.

Unlike its counterpart, IPolicyExportExtension, IPolicyImportExtension does not require implementation by a BindingElement object; you can load it using the client configuration section shown in the Examples section or programmatically by adding it to the System.ServiceModel.Description.WsdlImporter constructor.

Windows Communication Foundation (WCF) passes two objects to the ImportPolicy method, a MetadataImporter and a PolicyConversionContext. Typically the PolicyConversionContext object already contains the policy assertions for each binding scope.

An IPolicyImportExtension implementation performs the following steps:

  1. Locates the custom policy assertion for which it is responsible by calling either the GetBindingAssertions, GetMessageBindingAssertions, or GetOperationBindingAssertions methods, depending upon the scope.

  2. Removes the policy assertion from the assertion collection. The PolicyAssertionCollection.Remove method locates, returns, and removes the assertion in one step.

  3. Modify the binding stack or the contract by either adding a required custom BindingElement to the BindingElements property or by modifying the PolicyConversionContext.Contract property.

Step 2 is important. After all policy importers have been called, WCF checks for the existence of any policy assertions that remain. If one exists, WCF assumes that the policy import was unsuccessful and does not import the associated binding.


A malicious metadata supplier can attempt to send malformed XML as part of metadata in an attempt to exploit a policy importer. It is strongly recommended that custom policy importers be robust to all forms of XML that can be passed to it.

Custom MetadataImporter implementations must implement their own PolicyConversionContext object to extract the policy assertions attached to the custom metadata format.

If you want to export and import custom WSDL elements that are not policy assertions, see System.ServiceModel.Description.IWsdlExportExtension and System.ServiceModel.Description.IWsdlImportExtension.


You can use custom policy importers and exporters with the ServiceModel Metadata Utility Tool (Svcutil.exe) by using the same configuration elements in a configuration file and the /svcutilConfig:<configFile> option.

The following code example shows the use of the PolicyAssertionCollection.Remove method to locate, return, and remove the assertion in one step.

No code example is currently available or this language may not be supported.

The following code example shows the client application configuration file to load the custom policy importer when the System.ServiceModel.Description.MetadataResolver is invoked.

The following code example shows the use of the MetadataResolver to download and resolve metadata into description objects.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 3.0
Return to top