PolicyConversionContext Klasa

Definicja

Definiuje klasę używaną do pobierania asercji powiązań w metadanych i dołączania implementowania elementów powiązań w odpowiednim zakresie.

public ref class PolicyConversionContext abstract
public abstract class PolicyConversionContext
type PolicyConversionContext = class
Public MustInherit Class PolicyConversionContext
Dziedziczenie
PolicyConversionContext

Przykłady

Poniższy przykład kodu przedstawia implementację ImportPolicy metody, która zapisuje wszystkie asercji zasad w konsoli programu . Komentarze kodu opisują sposób lokalizowania określonego potwierdzenia zasad niestandardowych, tworzenia i wstawiania elementu powiązania implementowania oraz usuwania asercji z kolekcji.

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

Poniższy przykład kodu pokazuje, jak zarejestrować IPolicyImportExtension implementacje przy użyciu <policyImporters> sekcji konfiguracji.

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

Poniższy przykład kodu pokazuje, jak niestandardowy element powiązania może zaimplementować w IPolicyExportExtension celu dołączenia niestandardowej asercji zasad do asercji powiązań.

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);
    }
}

Uwagi

Implementacja PolicyConversionContext obiektu jest przekazywana do IPolicyExportExtension obiektów i IPolicyImportExtension do eksportowania i importowania, odpowiednio, asercji zasad niestandardowych do i z metadanych. Podczas eksportowania pobierana jest kolekcja asercji zasad w celu dodania asercji niestandardowych. Podczas importowania asercji są pobierane w celu zaimportowania określonych elementów i odpowiedniego skonfigurowania elementów powiązań.

Konstruktory

PolicyConversionContext(ServiceEndpoint)

Inicjuje PolicyConversionContext nowe wystąpienie klasy przy użyciu określonego punktu końcowego.

Właściwości

BindingElements

Pobiera kolekcję elementów powiązań, do których dodawane są niestandardowe elementy powiązania, które implementują asercji zasad.

Contract

Pobiera kontrakt dla punktu końcowego.

Metody

Equals(Object)

Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.

(Odziedziczone po Object)
GetBindingAssertions()

Pobiera kolekcję asercji zasad z metadanych.

GetFaultBindingAssertions(FaultDescription)

Zwraca kolekcję asercji zasad dla określonego błędu PROTOKOŁU SOAP.

GetHashCode()

Służy jako domyślna funkcja skrótu.

(Odziedziczone po Object)
GetMessageBindingAssertions(MessageDescription)

Pobiera kolekcję asercji zasad dla komunikatu.

GetOperationBindingAssertions(OperationDescription)

Zwraca kolekcję asercji zasad dla określonej operacji.

GetType()

Type Pobiera wartość bieżącego wystąpienia.

(Odziedziczone po Object)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Dotyczy