IPolicyExportExtension Gränssnitt
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Implementera IPolicyExportExtension för att infoga anpassade bindningsprincipkontroller i WSDL-information (Web Services Description Language).
public interface class IPolicyExportExtension
public interface IPolicyExportExtension
type IPolicyExportExtension = interface
Public Interface IPolicyExportExtension
- Härledda
Exempel
I följande kodexempel visas implementeringen av IPolicyExportExtension på en BindingElement. I det här exemplet kopplas ett anpassat bindningselement till WSDL-filen på bindningsnivå.
#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
I följande kodexempel visas en System.ServiceModel.Configuration.BindingElementExtensionElement implementering som gör att den föregående principexportören kan läsas in från en programkonfigurationsfil.
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
I följande exempel visas värdkonfigurationsfilen som läser in den anpassade principexportören.
<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>
I följande exempel visas den anpassade försäkran i WSDL-filen.
<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="" />
Kommentarer
IPolicyExportExtension Implementera gränssnittet på ett System.ServiceModel.Channels.BindingElement objekt för att skriva instruktioner om slutpunktsfunktioner eller krav i den WSDL-information som exponeras av en viss slutpunkt. Vanligtvis är bindningselementet ett som implementerar vissa funktioner, men detta krävs inte. Om du vill läsa in din principexportör från en konfigurationsfil implementerar du en System.ServiceModel.Configuration.BindingElementExtensionElement som returnerar principexportörobjektet BindingElement .
Principexportören används av Windows Communication Foundation (WCF) för att använda principkontroller för att kommunicera med klienter om förekomsten av det anpassade bindningskravet eller slutpunktsfunktionen.
Metoden ExportPolicy tar objekten MetadataExporter och PolicyConversionContext . GetBindingAssertionsAnvänd metoderna , GetMessageBindingAssertionsoch GetOperationBindingAssertions för att hämta samlingar av principkontroller som redan har exporterats i olika omfång. Lägg sedan till det anpassade principkontrollobjektet i lämplig samling.
Egenskapen Contract exponerar ContractDescription för slutpunkten som exporteras. På så IPolicyExportExtension sätt kan tillägget omfångsbegränsa sina exporterade principkontroller på rätt sätt. Säkerhetsattribut i kod kan till exempel lägga till beteenden till ContractDescription som anger var säkerhetsprincipkontroller ska läggas till.
Mekanismen IPolicyExportExtension stöder endast export av principkontroller i WSDL. Om du vill exportera anpassade WSDL-element måste du använda mekanismen IWsdlExportExtension för att ändra WSDL direkt.
När anpassade principkontroller har kopplats till WSDL-informationen kan klienter identifiera och importera anpassade bindningskontroller med hjälp av ett IPolicyImportExtension -objekt.
Metoder
| Name | Description |
|---|---|
| ExportPolicy(MetadataExporter, PolicyConversionContext) |
Implementera för att inkludera för export av en anpassad principkontroll om bindningar. |