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

The IPolicyImportExtension type exposes the following members.

  NameDescription
Public methodImportPolicyDefines a method that can import custom policy assertions and add implementing binding elements.
Top

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.

Important noteImportant

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.

NoteNote

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.

No code example is currently available or this language may not be supported.
<client>
    <endpoint 
      address="http://localhost:8080/StatefulService" 
      binding="wsHttpBinding"
      bindingConfiguration="CustomBinding_IStatefulService" 
      contract="IStatefulService"
      name="CustomBinding_IStatefulService" />
  <metadata>
    <policyImporters>
      <extension type="Microsoft.WCF.Documentation.CustomPolicyImporter, PolicyExtensions"/>
    </policyImporters>
  </metadata>
</client>

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

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft