IPolicyExportExtension 인터페이스

정의

WSDL(웹 서비스 기술 언어) 정보에 사용자 지정 바인딩 정책 어설션을 삽입하려면 IPolicyExportExtension을 구현합니다.

public interface class IPolicyExportExtension
public interface IPolicyExportExtension
type IPolicyExportExtension = interface
Public Interface IPolicyExportExtension
파생

예제

다음 코드 예제에서는 의 구현 IPolicyExportExtension 을 보여 입니다 BindingElement. 이 예제에서는 사용자 지정 바인딩 요소가 바인딩 수준에서 WSDL 파일에 연결됩니다.

#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

다음 코드 예제에서는 위의 정책 내보내기를 애플리케이션 구성 파일에서 로드할 수 있는 System.ServiceModel.Configuration.BindingElementExtensionElement 구현을 보여 줍니다.

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

다음 예제에서는 사용자 지정 정책 내보내기를 로드하는 호스트 구성 파일을 보여 줍니다.

<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>

다음 예제에서는 WSDL 파일의 사용자 지정 어설션을 보여 줍니다.

<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="" />

설명

특정 엔드포인트에서 공개한 WSDL 정보에 엔드포인트 기능 또는 요구 사항에 대한 명령문을 작성하려면 IPolicyExportExtension 개체에 대한 System.ServiceModel.Channels.BindingElement 인터페이스를 구현합니다. 일반적으로 바인딩 요소는 일부 기능을 구현하는 요소이지만 필수는 아닙니다. 구성 파일에서 정책 내보내기를 로드하려면 정책 내보내기 개체를 System.ServiceModel.Configuration.BindingElementExtensionElement 반환하는 을 BindingElement 구현합니다.

정책 내보내기는 WCF(Windows Communication Foundation)에서 정책 어설션을 사용하여 해당 사용자 지정 바인딩 요구 사항 또는 엔드포인트 기능의 존재를 클라이언트와 통신하는 데 사용됩니다.

메서드는 ExportPolicyPolicyConversionContext 개체를 MetadataExporter 사용합니다. 다양한 범위에서 이미 내보낸 정책 어설션 컬렉션을 가져오려면 GetBindingAssertions, GetMessageBindingAssertionsGetOperationBindingAssertions 메서드를 사용합니다. 그런 다음 사용자 지정 정책 어설션 개체를 적절한 컬렉션에 추가합니다.

Contract 속성은 내보낼 엔드포인트에 대한 ContractDescription을 공개합니다. 이렇게 하면 확장에서 IPolicyExportExtension 내보낸 정책 어설션을 올바르게 scope 수 있습니다. 예를 들어, 코드의 보안 특성을 사용하여 보안 정책 어설션을 추가할 위치를 나타내는 동작을 ContractDescription에 추가할 수 있습니다.

이 메커니즘은 IPolicyExportExtension WSDL에서 정책 어설션 내보내기만 지원합니다. 사용자 지정 WSDL 요소를 내보내려면 메커니즘을 IWsdlExportExtension 사용하여 WSDL을 직접 수정해야 합니다.

사용자 지정 정책 어설션이 WSDL 정보에 연결되면 클라이언트는 개체를 사용하여 IPolicyImportExtension 사용자 지정 바인딩 어설션을 검색하고 가져올 수 있습니다.

메서드

ExportPolicy(MetadataExporter, PolicyConversionContext)

바인딩에 대한 사용자 지정 어설션을 내보내기 위해 포함할 구현입니다.

적용 대상