IPolicyExportExtension.ExportPolicy Method (MetadataExporter, PolicyConversionContext)

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

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

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

void ExportPolicy(
	MetadataExporter exporter,
	PolicyConversionContext context
)

Parameters

exporter
Type: System.ServiceModel.Description.MetadataExporter

The MetadataExporter that you can use to modify the exporting process.

context
Type: System.ServiceModel.Description.PolicyConversionContext

The PolicyConversionContext that you can use to insert your custom policy assertion.

Use the GetBindingAssertions, GetMessageBindingAssertions, and GetOperationBindingAssertions methods to obtain collections of policy assertions that have already been exported at various scopes. Then add your IPolicyExportExtension object to the appropriate collection.

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 void ExportPolicy(MetadataExporter exporter, PolicyConversionContext policyContext)
{
  if (exporter == null)
    throw new NullReferenceException("The MetadataExporter object passed to the ExporterBindingElement is null.");
  if (policyContext == null)
    throw new NullReferenceException("The PolicyConversionContext object passed to the ExporterBindingElement is null.");

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

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 : BindingElementExtensionElement
{
  public ExporterBindingElementConfigurationSection()
  { Console.WriteLine("Exporter configuration section created."); }

  public override Type BindingElementType
  { get { return typeof(ExporterBindingElement); } }

  protected override BindingElement CreateBindingElement()
  { return new ExporterBindingElement(); }
}

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: