Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

IPolicyExportExtension Interface

 

Implement IPolicyExportExtension to insert custom binding policy assertions in the Web Services Description Language (WSDL) information.

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

Public Interface IPolicyExportExtension

NameDescription
System_CAPS_pubmethodExportPolicy(MetadataExporter, PolicyConversionContext)

Implement to include for exporting a custom policy assertion about bindings.

Implement the IPolicyExportExtension interface on a System.ServiceModel.Channels.BindingElement object to write statements about endpoint capabilities or requirements into the WSDL information exposed by a particular endpoint. Typically the binding element is one that implements some feature, but this is not required. To load your policy exporter from a configuration file, implement a System.ServiceModel.Configuration.BindingElementExtensionElement that returns the policy exporter BindingElement object.

The policy exporter is used by Windows Communication Foundation (WCF) to use policy assertions to communicate to clients the existence of that custom binding requirement or endpoint capability.

The ExportPolicy method takes the MetadataExporter and PolicyConversionContext objects. Use the GetBindingAssertions, GetMessageBindingAssertions, and GetOperationBindingAssertions methods to obtain collections of policy assertions that have already been exported at various scopes. Then add your custom policy assertion object to the appropriate collection.

The Contract property exposes the ContractDescription for the endpoint that is being exported. This allows the IPolicyExportExtension extension to correctly scope their exported policy assertions. For example, security attributes in code may add behaviors to the ContractDescription that indicate where security policy assertions should be added.

The IPolicyExportExtension mechanism only supports exporting policy assertions in WSDL. To export custom WSDL elements you must use the IWsdlExportExtension mechanism to modify the WSDL directly.

Once custom policy assertions have been attached to the WSDL information, clients can detect and import the custom binding assertions by using an IPolicyImportExtension object.

The following code example shows the implementation of IPolicyExportExtension on a BindingElement. In this example, a custom binding element is attached to the WSDL file at the binding level.

#Region "IPolicyExporter Members"
Public Sub ExportPolicy(ByVal exporter As MetadataExporter, ByVal policyContext As PolicyConversionContext) Implements IPolicyExportExtension.ExportPolicy
  If exporter Is Nothing Then
	Throw New NullReferenceException("The MetadataExporter object passed to the ExporterBindingElement is null.")
  End If
  If policyContext Is Nothing Then
	Throw New NullReferenceException("The PolicyConversionContext object passed to the ExporterBindingElement is null.")
  End If

  Dim elem As XmlElement = doc.CreateElement(name1, ns1)
  elem.InnerText = "My custom text."
  Dim att As XmlAttribute = doc.CreateAttribute("MyCustomAttribute", ns1)
  att.Value = "ExampleValue"
  elem.Attributes.Append(att)
  Dim subElement As XmlElement = doc.CreateElement("MyCustomSubElement", ns1)
  subElement.InnerText = "Custom Subelement Text."
  elem.AppendChild(subElement)
  policyContext.GetBindingAssertions().Add(elem)
  Console.WriteLine("The custom policy exporter was called.")
End Sub
#End Region

The following code example shows a System.ServiceModel.Configuration.BindingElementExtensionElement implementation that enables the preceding policy exporter to be loaded from an application configuration file.

 Public Class ExporterBindingElementConfigurationSection
  Inherits BindingElementExtensionElement
Public Sub New()
	Console.WriteLine("Exporter configuration section created.")
End Sub

Public Overrides ReadOnly Property BindingElementType() As Type
	Get
		Return GetType(ExporterBindingElement)
	End Get
End Property

Protected Overrides Function CreateBindingElement() As BindingElement
	Return New ExporterBindingElement()
End Function
 End Class

The following example shows the host configuration file that loads the custom policy exporter.

The following example shows the custom assertion in the WSDL file.

.NET Framework
Available since 3.0
Return to top
Show:
© 2017 Microsoft