PolicyConversionContext 클래스

정의

메타데이터에서 바인딩 어설션을 검색하고 해당 범위에서 구현 바인딩 요소를 연결하는 데 사용되는 클래스를 정의합니다.

public ref class PolicyConversionContext abstract
public abstract class PolicyConversionContext
type PolicyConversionContext = class
Public MustInherit Class PolicyConversionContext
상속
PolicyConversionContext

예제

다음 코드 예제에서는 콘솔에 모든 정책 어설션을 쓰는 ImportPolicy 메서드 구현을 보여 줍니다. 코드 주석에서는 특정 사용자 지정 정책 어설션을 검색하고, 구현 바인딩 요소를 생성 및 삽입하며, 컬렉션에서 어설션을 제거하는 방법을 설명합니다.

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.
          context.GetBindingAssertions().Remove(customAssertion);
          Console.WriteLine(
            "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);
              context.BindingElements.Add(e);
            */
        }

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

        //write contents in gray.
        Console.WriteLine(assertion.OuterXml);
        Console.ForegroundColor = ConsoleColor.Gray;
    }
}

다음 코드 예제에서는 IPolicyImportExtension 구성 섹션을 사용하여 <policyImporters> 구현을 등록하는 방법을 보여 줍니다.

<configuration>
  <system.serviceModel>
    <client>
      <metadata>
        <policyImporters>
          <extension type="CustomPolicyImporter, assembly"/>
        </policyImporters>
      </metadata>
    </client>
  </system.serviceModel>
</configuration>

다음 코드 예제에서는 사용자 지정 바인딩 요소에서 IPolicyExportExtension을 구현하여 사용자 지정 정책 어설션을 바인딩 어설션에 연결하는 방법을 보여 줍니다.

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

    public void ExportPolicy(
     MetadataExporter exporter, PolicyConversionContext context)
    {
        XmlDocument xmlDoc = new XmlDocument();
        XmlElement xmlElement =
               xmlDoc.CreateElement("MyPolicyAssertion");
        context.GetBindingAssertions().Add(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 =
            ContractDescription.GetContract(typeof(MyContract));
        ServiceEndpoint endpoint =
            new ServiceEndpoint(contract, customBinding, address);
        MetadataExporter exporter = new WsdlExporter();
        exporter.ExportEndpoint(endpoint);
    }
}

설명

PolicyConversionContext 구현을 IPolicyExportExtension 개체에 전달하여 내보내거나, IPolicyImportExtension 개체에 전달하여 메타데이터에서 사용자 지정 정책 어설션을 가져옵니다. 내보낼 때는 사용자 지정 어설션을 추가하기 위해 정책 어설션 컬렉션이 검색됩니다. 가져올 때에는 어설션을 검색하여 특정 어설션을 가져온 다음 바인딩 요소가 적절하게 구성됩니다.

  • GetBindingAssertions 메서드는 바인딩에 대한 모든 정책 어설션을 반환합니다.

  • GetFaultBindingAssertions 메서드는 특정 오류 메시지에 대한 모든 정책 어설션을 반환합니다.

  • GetMessageBindingAssertions 메서드는 특정 메시지에 대한 모든 정책 어설션을 반환합니다.

  • GetOperationBindingAssertions 메서드는 특정 작업에 대한 모든 정책 어설션을 반환합니다.

  • BindingElements 속성은 설명하거나 구성할 바인딩에 대한 바인딩 요소를 가져옵니다.

  • Contract 속성은 바인딩을 설명하거나 구성할 계약 설명을 가져옵니다.

생성자

PolicyConversionContext(ServiceEndpoint)

지정된 엔드포인트를 사용하여 PolicyConversionContext 클래스의 새 인스턴스를 초기화합니다.

속성

BindingElements

정책 어설션을 구현하는 사용자 지정 바인딩 요소가 추가될 바인딩 요소 컬렉션을 가져옵니다.

Contract

엔드포인트에 대한 계약을 가져옵니다.

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetBindingAssertions()

메타데이터에서 정책 어설션 컬렉션을 가져옵니다.

GetFaultBindingAssertions(FaultDescription)

지정한 SOAP 오류에 대한 정책 어설션 컬렉션을 반환합니다.

GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetMessageBindingAssertions(MessageDescription)

메시지에 대한 정책 어설션 컬렉션을 가져옵니다.

GetOperationBindingAssertions(OperationDescription)

지정한 작업에 대한 정책 어설션 컬렉션을 반환합니다.

GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상