Aracılığıyla paylaş


IPolicyImportExtension Arabirim

Tanım

Bağlamalar hakkında özel ilke onaylarını içeri aktaran nesneler için bir yöntem tanımlar.

public interface class IPolicyImportExtension
public interface IPolicyImportExtension
type IPolicyImportExtension = interface
Public Interface IPolicyImportExtension
Türetilmiş

Örnekler

Aşağıdaki kod örneği, bir adımda onaylamayı bulmak, döndürmek ve kaldırmak için yönteminin kullanımını PolicyAssertionCollection.Remove gösterir.

  #region IPolicyImporter Members
  public const string name1 = "acme";
  public const string ns1 = "http://Microsoft/WCF/Documentation/CustomPolicyAssertions";

  /*
   * Importing policy assertions usually means modifying the bindingelement stack in some way
   * to support the policy assertion. The procedure is:
   * 1. Find the custom assertion to import.
   * 2. Insert a supporting custom bindingelement or modify the current binding element collection
   *     to support the assertion.
   * 3. Remove the assertion from the collection. Once the ImportPolicy method has returned,
   *     any remaining assertions for the binding cause the binding to fail import and not be
   *     constructed.
   */
  public void ImportPolicy(MetadataImporter importer, PolicyConversionContext context)
  {
    Console.WriteLine("The custom policy importer has been called.");
    // Locate the custom assertion and remove it.
    XmlElement customAssertion = context.GetBindingAssertions().Remove(name1, ns1);
    if (customAssertion != null)
    {
      Console.WriteLine(
        "Removed our custom assertion from the imported "
        + "assertions collection and inserting our custom binding element."
      );
      // Here we would add the binding modification that implemented the policy.
      // This sample does not do this.
      Console.ForegroundColor = ConsoleColor.Red;
      Console.WriteLine(customAssertion.NamespaceURI + " : " + customAssertion.Name);
      Console.WriteLine(customAssertion.OuterXml);
      Console.ForegroundColor = ConsoleColor.Gray;
    }
 }
#endregion
    #Region "IPolicyImporter Members"
    Public Const name1 As String = "acme"
    Public Const ns1 As String = "http://Microsoft/WCF/Documentation/CustomPolicyAssertions"

'    
'     * Importing policy assertions usually means modifying the bindingelement stack in some way
'     * to support the policy assertion. The procedure is:
'     * 1. Find the custom assertion to import.
'     * 2. Insert a supporting custom bindingelement or modify the current binding element collection
'     *     to support the assertion.
'     * 3. Remove the assertion from the collection. Once the ImportPolicy method has returned, 
'     *     any remaining assertions for the binding cause the binding to fail import and not be 
'     *     constructed.
'     
    Public Sub ImportPolicy(ByVal importer As MetadataImporter, ByVal context As PolicyConversionContext) Implements IPolicyImportExtension.ImportPolicy
      Console.WriteLine("The custom policy importer has been called.")
      ' Locate the custom assertion and remove it.
      Dim customAssertion As XmlElement = context.GetBindingAssertions().Remove(name1, ns1)
      If customAssertion IsNot Nothing Then
        Console.WriteLine("Removed our custom assertion from the imported " & "assertions collection and inserting our custom binding element.")
        ' Here we would add the binding modification that implemented the policy.
        ' This sample does not do this.
        Console.ForegroundColor = ConsoleColor.Red
        Console.WriteLine(customAssertion.NamespaceURI & " : " & customAssertion.Name)
        Console.WriteLine(customAssertion.OuterXml)
        Console.ForegroundColor = ConsoleColor.Gray
      End If
    End Sub
  #End Region

Aşağıdaki kod örneği, çağrıldığında System.ServiceModel.Description.MetadataResolver özel ilke içeri aktarıcısını yüklemek için istemci uygulaması yapılandırma dosyasını gösterir.

<client>
    <endpoint 
      address="http://localhost:8080/StatefulService" 
      binding="wsHttpBinding"
      bindingConfiguration="CustomBinding_IStatefulService" 
      contract="IStatefulService"
      name="CustomBinding_IStatefulService" />
  <metadata>
    <policyImporters>
      <extension type="Microsoft.WCF.Documentation.CustomPolicyImporter, PolicyExtensions"/>
    </policyImporters>
  </metadata>
</client>

Aşağıdaki kod örneği, meta verileri indirmek ve açıklama nesnelerine çözümlemek için uygulamasının MetadataResolver kullanımını gösterir.

// Download all metadata.
ServiceEndpointCollection endpoints
  = MetadataResolver.Resolve(
    typeof(IStatefulService),
    new EndpointAddress("http://localhost:8080/StatefulService/mex")
  );
' Download all metadata. 
Dim endpoints As ServiceEndpointCollection = MetadataResolver.Resolve(GetType(IStatefulService), New EndpointAddress("http://localhost:8080/StatefulService/mex"))

Açıklamalar

IPolicyImportExtension Uç nokta özellikleri veya gereksinimleri hakkında özel ilke onayları için belirli bir uç nokta tarafından kullanıma sunulan WSDL bilgilerini aramak için arabirimini uygulayın. Genellikle, bir ilke içeri aktarıcısı belirli bir onaylamayı arar ve bir bağlama öğesi ekler, bağlama öğesi yapılandırılır veya onay gereksinimlerini desteklemek için sözleşmeyi değiştirir.

karşılık gelen öğesinden farklı olarak, IPolicyExportExtensionIPolicyImportExtension bir BindingElement nesne tarafından uygulanması gerekmez; Örnekler bölümünde gösterilen istemci yapılandırması bölümünü kullanarak veya oluşturucuya System.ServiceModel.Description.WsdlImporter ekleyerek program aracılığıyla yükleyebilirsiniz.

Windows Communication Foundation (WCF) yöntemine ImportPolicy iki nesne geçirir: a MetadataImporter ve .PolicyConversionContext PolicyConversionContext Genellikle nesne zaten her bağlama kapsamı için ilke onaylarını içerir.

Bir IPolicyImportExtension uygulama aşağıdaki adımları gerçekleştirir:

  1. Kapsamına bağlı olarak , GetMessageBindingAssertionsveya GetOperationBindingAssertions yöntemlerini çağırarak GetBindingAssertionssorumlu olduğu özel ilke onayını bulur.

  2. onay koleksiyonundan ilke onayını kaldırır. yöntemi bir PolicyAssertionCollection.Remove adımda onaylama işlemini bulur, döndürür ve kaldırır.

  3. Bağlama yığınını veya sözleşmeyi, özelliğine BindingElements gerekli bir özel BindingElement öğe ekleyerek veya özelliğini değiştirerek PolicyConversionContext.Contract değiştirin.

2. adım önemlidir. Tüm ilke içeri aktarıcıları çağrıldıktan sonra WCF, kalan ilke onaylarının varlığını denetler. Varsa, WCF ilke içeri aktarma işleminin başarısız olduğunu ve ilişkili bağlamayı içeri aktarmadığını varsayar.

Önemli

Kötü amaçlı meta veri sağlayıcısı, bir ilke içeri aktarıcıdan yararlanma girişiminde meta verilerin bir parçası olarak hatalı biçimlendirilmiş XML göndermeye çalışabilir. Özel ilke içeri aktarıcılarının, ona geçirilebilen tüm XML biçimlerine dayanıklı olması kesinlikle önerilir.

Özel MetadataImporter uygulamalar, özel meta veri biçimine ekli ilke onaylarını ayıklamak için kendi PolicyConversionContext nesnesini uygulamalıdır.

İlke onayları olmayan özel WSDL öğelerini dışarı ve içeri aktarmak istiyorsanız, bkz System.ServiceModel.Description.IWsdlExportExtension . ve System.ServiceModel.Description.IWsdlImportExtension.

Uyarı

Bir yapılandırma dosyasındaki aynı yapılandırma öğelerini ve seçeneğini kullanarak ServiceModel Meta Veri Yardımcı Programı Aracı (Svcutil.exe) ile özel ilke içeri aktarıcılarını ve dışarı aktarıcılarını /svcutilConfig:<configFile> kullanabilirsiniz.

Yöntemler

Name Description
ImportPolicy(MetadataImporter, PolicyConversionContext)

Özel ilke onaylarını içeri aktarabilen ve uygulayan bağlama öğeleri ekleyebilen bir yöntem tanımlar.

Şunlara uygulanır