IPolicyImportExtension::ImportPolicy Method (MetadataImporter^, PolicyConversionContext^)
Defines a method that can import custom policy assertions and add implementing binding elements.
Assembly: System.ServiceModel (in System.ServiceModel.dll)
Parameters
- importer
-
Type:
System.ServiceModel.Description::MetadataImporter^
The MetadataImporter object in use.
- context
-
Type:
System.ServiceModel.Description::PolicyConversionContext^
The PolicyConversionContext that contains both the policy assertions that can be imported and the collections of binding elements to which implementing binding elements can be added.
Implement the ImportPolicy method to obtain policy assertions and perform some modification of the imported contract or binding to support the assertion. Typically, a policy importer responds to finding a custom policy assertion by configuring or inserting a binding element into the binding being imported.
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:
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.
Modifies 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.
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.
The following code example shows the use of the MetadataResolver to download and resolve metadata into description objects.
Available since 3.0