IPolicyExportExtension Interface
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Implementeer IPolicyExportExtension om aangepaste bindingsbeleidsverklaringen in te voegen in de WSDL-informatie (Web Services Description Language).
public interface class IPolicyExportExtension
public interface IPolicyExportExtension
type IPolicyExportExtension = interface
Public Interface IPolicyExportExtension
- Afgeleid
Voorbeelden
In het volgende codevoorbeeld ziet u de implementatie van IPolicyExportExtension een BindingElement. In dit voorbeeld wordt een aangepast bindingselement gekoppeld aan het WSDL-bestand op bindingsniveau.
#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
#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
In het volgende codevoorbeeld ziet u een System.ServiceModel.Configuration.BindingElementExtensionElement implementatie waarmee de voorgaande beleidsexporteur kan worden geladen vanuit een toepassingsconfiguratiebestand.
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(); }
}
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
In het volgende voorbeeld ziet u het hostconfiguratiebestand waarmee de aangepaste beleidsexporteur wordt geladen.
<system.serviceModel>
<services>
<service
name="Microsoft.WCF.Documentation.StatefulService"
behaviorConfiguration="addMetadata"
>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/StatefulService"/>
</baseAddresses>
</host>
<endpoint
address="http://localhost:8080/StatefulService"
binding="customBinding"
bindingConfiguration="exporter"
contract="Microsoft.WCF.Documentation.IStatefulService"
/>
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"
/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="addMetadata">
<serviceMetadata
httpGetEnabled="true"
httpGetUrl=""
/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<customBinding>
<!--
Use the name attribute of the binding element as
the value of the bindingConfiguration attribute in
your endpoint.
-->
<binding name ="exporter">
<!-- Use the name attribute of your binding element extension specified below. -->
<!-- Be certain the order of your custom binding elements is correct. -->
<exporterBinding />
<reliableSession/>
<textMessageEncoding messageVersion="Default" />
<httpTransport/>
</binding>
</customBinding>
</bindings>
<extensions>
<bindingElementExtensions>
<!-- Use the add element to associate your bindingelement configuration handler and give it a name to use. -->
<add
type="Microsoft.WCF.Documentation.ExporterBindingElementConfigurationSection,PolicyExtensions"
name="exporterBinding" />
</bindingElementExtensions>
</extensions>
</system.serviceModel>
In het volgende voorbeeld ziet u de aangepaste assertie in het WSDL-bestand.
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
namespaces removed here for clarity...
>
<wsp:Policy wsu:Id="CustomBinding_IStatefulService_policy">
<wsp:ExactlyOne>
<wsp:All>
<acme
b:MyCustomAttribute="ExampleValue"
xmlns="http://Microsoft/WCF/Documentation/CustomPolicyAssertions" xmlns:b="http://Microsoft/WCF/Documentation/CustomPolicyAssertions">
My custom text.
<MyCustomSubElement>Custom Subelement Text.</MyCustomSubElement>
</acme>
<wsrm:RMAssertion xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm/policy">
<wsrm:InactivityTimeout Milliseconds="600000" />
<wsrm:AcknowledgementInterval Milliseconds="200" />
</wsrm:RMAssertion>
<wsaw:UsingAddressing />
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
<wsdl:import namespace="http://microsoft.wcf.documentation" location="" />
Opmerkingen
Implementeer de IPolicyExportExtension interface op een System.ServiceModel.Channels.BindingElement object om instructies te schrijven over de mogelijkheden of vereisten van eindpunten in de WSDL-informatie die door een bepaald eindpunt wordt weergegeven. Doorgaans is het bindingselement een element dat een bepaalde functie implementeert, maar dit is niet vereist. Als u de beleidsexporteur wilt laden vanuit een configuratiebestand, implementeert u een System.ServiceModel.Configuration.BindingElementExtensionElement bestand dat het object beleidsexporteur retourneert BindingElement .
De beleidsexporteur wordt gebruikt door Windows Communication Foundation (WCF) om beleidsverklaringen te gebruiken om clients te laten communiceren met het bestaan van die aangepaste bindingsvereiste of eindpuntmogelijkheid.
De ExportPolicy methode gebruikt de MetadataExporter en PolicyConversionContext objecten. Gebruik de GetBindingAssertions, GetMessageBindingAssertionsen GetOperationBindingAssertions methoden om verzamelingen beleidsverklaringen te verkrijgen die al zijn geëxporteerd op verschillende bereiken. Voeg vervolgens uw aangepaste beleidsbevestigingsobject toe aan de juiste verzameling.
De Contract eigenschap toont het ContractDescription voor het eindpunt dat wordt geëxporteerd. Hierdoor kan de IPolicyExportExtension extensie de geëxporteerde beleidsverklaringen correct bepalen. Beveiligingskenmerken in code kunnen bijvoorbeeld gedrag toevoegen aan de ContractDescription kenmerken die aangeven waar beveiligingsbeleidsverklaringen moeten worden toegevoegd.
Het IPolicyExportExtension mechanisme biedt alleen ondersteuning voor het exporteren van beleidsverklaringen in WSDL. Als u aangepaste WSDL-elementen wilt exporteren, moet u het IWsdlExportExtension mechanisme gebruiken om de WSDL rechtstreeks te wijzigen.
Zodra aangepaste beleidsverklaringen zijn gekoppeld aan de WSDL-informatie, kunnen clients de aangepaste bindingsverklaringen detecteren en importeren met behulp van een IPolicyImportExtension object.
Methoden
| Name | Description |
|---|---|
| ExportPolicy(MetadataExporter, PolicyConversionContext) |
Implementeren om op te nemen voor het exporteren van een aangepaste beleidsverklaring over bindingen. |