Diese Dokumentation wurde archiviert und wird nicht länger gepflegt.


Gets a collection of policy assertions from metadata.

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

public abstract PolicyAssertionCollection GetBindingAssertions ()
public abstract PolicyAssertionCollection GetBindingAssertions ()
public abstract function GetBindingAssertions () : PolicyAssertionCollection
Nicht zutreffend.


An ICollection of type XmlElement that contains binding policy assertions.

The collection returned from GetBindingAssertions is not a copy. You can add and remove assertions as necessary.

The following code example shows an implementation of the ImportPolicy method that writes all policy assertions to the console. The code comments describe how to locate a specific custom policy assertion, create and insert an implementing binding element, and remove the assertion from the collection.

public void ImportPolicy(MetadataImporter importer, 
    PolicyConversionContext context)
    Console.WriteLine("The custom policy importer has been called.");
    foreach (XmlElement assertion in context.GetBindingAssertions())
        Console.WriteLine(assertion.NamespaceURI + " : " + assertion.Name);
        // locate a particular assertion by Name and NamespaceURI
        XmlElement customAssertion = context.GetBindingAssertions().Find(name1, ns1);
        if (customAssertion != null)
          // Found assertion; remove from collection.
            "Removed our custom assertion from the imported "
            + "assertions collection and inserting our custom binding element."
            // Here if you find the custom policy assertion that you are looking for,
            // add the custom binding element that handles the functionality that the policy indicates.
            // Attach it to the PolicyConversionContext.BindingElements collection.
            // For example, if the custom policy had a "speed" attribute value:
              string speed 
                = customAssertion.GetAttribute(SpeedBindingElement.name2, SpeedBindingElement.ns2);
              SpeedBindingElement e = new SpeedBindingElement(speed);

        // write assertion name in red.
        Console.ForegroundColor = ConsoleColor.Red;
        Console.WriteLine(assertion.NamespaceURI + " : " + assertion.Name);

        //write contents in gray.
        Console.ForegroundColor = ConsoleColor.Gray; 

The following code example shows how to register IPolicyImportExtension implementations using the <policyImporters> configuration section.

        <add type="CustomPolicyImporter, assembly"/>

The following code example demonstrates how a custom binding element can implement IPolicyExportExtension to attach a custom policy assertion to the binding assertions.

public class MyBindingElement : BindingElement, IPolicyExportExtension
// BindingElement implementation . . .

    public void ExportPolicy(
     MetadataExporter exporter, PolicyConversionContext context)
        XmlDocument xmlDoc = new XmlDocument();
        XmlElement xmlElement = 

    // Note: All custom binding elements must return a deep clone 
    // to enable the run time to support multiple bindings using the 
    // same custom binding.
    public override BindingElement Clone()
        // this is just a placeholder
        return null;

    // Call the inner property.
    public override T GetProperty<T>(BindingContext context)
        return context.GetInnerProperty<T>();


public class Program {
    public static void Main(string[] args) {
        EndpointAddress address = 
            new EndpointAddress("http://localhost/metadata");
        CustomBinding customBinding = 
            new CustomBinding(new BasicHttpBinding());
        customBinding.Elements.Add(new MyBindingElement());
        ContractDescription contract =
        ServiceEndpoint endpoint = 
            new ServiceEndpoint(contract, customBinding, address);
        MetadataExporter exporter = new WsdlExporter();

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

Microsoft .NET Framework 3.0 wird unter Windows Vista, Microsoft Windows XP SP2 und Windows Server 2003 SP1 unterstützt.

.NET Framework

Unterstützt in: 3.0