Defines a method for objects that import custom policy assertions about bindings.
Assembly: System.ServiceModel (in System.ServiceModel.dll)
Thetype exposes the following members.
Implement the 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, 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 implementation performs the following steps:
Locates the custom policy assertion for which it is responsible by calling either the GetBindingAssertions, GetMessageBindingAssertions, or GetOperationBindingAssertions methods, depending upon the scope.
Removes the policy assertion from the assertion collection. The PolicyAssertionCollection::Remove method locates, returns, and removes the assertion in one step.
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.
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.
The following code example shows the client application configuration file to load the custom policy importer when the System.ServiceModel.Description::MetadataResolver is invoked.
<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.
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.