IPolicyExportExtension Interface
Definição
Implementa IPolicyExportExtension para inserir declarações de política de associação personalizadas nas informações da WSDL (linguagem WSDL).Implement IPolicyExportExtension to insert custom binding policy assertions in the Web Services Description Language (WSDL) information.
public interface class IPolicyExportExtension
public interface IPolicyExportExtension
type IPolicyExportExtension = interface
Public Interface IPolicyExportExtension
- Derivado
Exemplos
O exemplo de código a seguir mostra a implementação de IPolicyExportExtension em um BindingElement .The following code example shows the implementation of IPolicyExportExtension on a BindingElement. Neste exemplo, um elemento de associação personalizado é anexado ao arquivo WSDL no nível de associação.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
#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
O exemplo de código a seguir mostra uma System.ServiceModel.Configuration.BindingElementExtensionElement implementação que permite que o exportador de diretiva anterior seja carregado a partir de um arquivo de configuração de aplicativo.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(); }
}
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
O exemplo a seguir mostra o arquivo de configuração de host que carrega o exportador de política personalizada.The following example shows the host configuration file that loads the custom policy exporter.
<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>
O exemplo a seguir mostra a declaração personalizada no arquivo WSDL.The following example shows the custom assertion in the WSDL file.
<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="" />
Comentários
Implemente a IPolicyExportExtension interface em um System.ServiceModel.Channels.BindingElement objeto para escrever instruções sobre recursos de ponto de extremidade ou requisitos nas informações WSDL expostas por um ponto de extremidade específico.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. Normalmente, o elemento de associação é um que implementa algum recurso, mas isso não é necessário.Typically the binding element is one that implements some feature, but this is not required. Para carregar o exportador de política de um arquivo de configuração, implemente um System.ServiceModel.Configuration.BindingElementExtensionElement que retorne o objeto de exportador de política BindingElement .To load your policy exporter from a configuration file, implement a System.ServiceModel.Configuration.BindingElementExtensionElement that returns the policy exporter BindingElement object.
O exportador de política é usado pelo Windows Communication Foundation (WCF) para usar declarações de política para se comunicar com os clientes a existência desse requisito de associação personalizado ou capacidade de ponto de extremidade.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.
O ExportPolicy método usa os MetadataExporter PolicyConversionContext objetos e.The ExportPolicy method takes the MetadataExporter and PolicyConversionContext objects. Use os GetBindingAssertions GetMessageBindingAssertions métodos, e GetOperationBindingAssertions para obter coleções de declarações de política que já foram exportadas em vários escopos.Use the GetBindingAssertions, GetMessageBindingAssertions, and GetOperationBindingAssertions methods to obtain collections of policy assertions that have already been exported at various scopes. Em seguida, adicione o objeto de declaração de política personalizada à coleção apropriada.Then add your custom policy assertion object to the appropriate collection.
A Contract Propriedade expõe o ContractDescription para o ponto de extremidade que está sendo exportado.The Contract property exposes the ContractDescription for the endpoint that is being exported. Isso permite que a IPolicyExportExtension extensão alcance corretamente suas asserções de política exportadas.This allows the IPolicyExportExtension extension to correctly scope their exported policy assertions. Por exemplo, os atributos de segurança no código podem adicionar comportamentos ao ContractDescription que indicam onde as declarações de política de segurança devem ser adicionadas.For example, security attributes in code may add behaviors to the ContractDescription that indicate where security policy assertions should be added.
O IPolicyExportExtension mecanismo só dá suporte à exportação de declarações de política no WSDL.The IPolicyExportExtension mechanism only supports exporting policy assertions in WSDL. Para exportar elementos WSDL personalizados, você deve usar o IWsdlExportExtension mecanismo para modificar o WSDL diretamente.To export custom WSDL elements you must use the IWsdlExportExtension mechanism to modify the WSDL directly.
Depois que as declarações de política personalizadas tiverem sido anexadas às informações de WSDL, os clientes poderão detectar e importar as asserções de associação personalizadas usando um IPolicyImportExtension objeto.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.
Métodos
| ExportPolicy(MetadataExporter, PolicyConversionContext) |
Implementar na inclusão para exportar uma declaração de política personalizada sobre associações.Implement to include for exporting a custom policy assertion about bindings. |