Aracılığıyla paylaş


Nasıl yapılır: Hizmet Uç Noktalarından Meta Verileri Dışa Aktarma

Bu konuda, hizmet uç noktalarından meta verilerin nasıl dışarı aktarılası açıklanmaktadır.

Hizmet uç noktalarından meta verileri dışarı aktarmak için

  1. Yeni bir Visual Studio Konsol Uygulaması Projesi oluşturun. Aşağıdaki adımlarda gösterilen kodu main() yöntemi içinde oluşturulan Program.cs dosyasına ekleyin.

  2. oluşturun WsdlExporter.

    WsdlExporter exporter = new WsdlExporter();
    
    Dim exporter As New WsdlExporter()
    
  3. PolicyVersion özelliğini numaralandırmadaki değerlerden PolicyVersion birine ayarlayın. Bu örnek, WS-policy 1.5'e karşılık gelen değeri Policy15 ayarlar.

    exporter.PolicyVersion = PolicyVersion.Policy15;
    
    exporter.PolicyVersion = PolicyVersion.Policy15
    
  4. Bir nesne dizisi ServiceEndpoint oluşturun.

    ServiceEndpoint [] myServiceEndpoints = new ServiceEndpoint[2];
    ContractDescription myDescription = new ContractDescription ("myContract");
    myServiceEndpoints[0] = new ServiceEndpoint(myDescription,new BasicHttpBinding(),new EndpointAddress("http://localhost/myservice"));
    myServiceEndpoints[1] = new ServiceEndpoint(myDescription,new BasicHttpBinding(),new EndpointAddress("http://localhost/myservice"));
    
    Dim myServiceEndpoints() As ServiceEndpoint = New ServiceEndpoint(1) {}
    Dim myDescription As New ContractDescription("myContract")
    myServiceEndpoints(0) = New ServiceEndpoint(myDescription, New BasicHttpBinding(), New EndpointAddress("http://localhost/myservice"))
    myServiceEndpoints(1) = New ServiceEndpoint(myDescription, New BasicHttpBinding(), New EndpointAddress("http://localhost/myservice"))
    
  5. Her hizmet uç noktası için meta verileri dışarı aktarın.

    // Export all endpoints for each endpoint in collection.
    foreach (ServiceEndpoint endpoint in myServiceEndpoints)
    {
        exporter.ExportEndpoint(endpoint);
    }
    
    'Export all endpoints for each endpoint in collection.
    For Each endpoint As ServiceEndpoint In myServiceEndpoints
        exporter.ExportEndpoint(endpoint)
    Next
    
  6. Dışarı aktarma işlemi sırasında hata oluşmadığından emin olun ve meta verileri alın.

    // If there are no errors, get the documents.
    MetadataSet metadataDocs = null;
    if (exporter.Errors.Count != 0)
    {
        metadataDocs = exporter.GetGeneratedMetadata();
    }
    
    'If there are no errors, get the documents.
    Dim metadataDocs As MetadataSet
    metadataDocs = Nothing
    
    If (exporter.Errors.Count = 0) Then
        metadataDocs = exporter.GetGeneratedMetadata()
    End If
    
  7. Artık yöntemini çağırarak WriteTo(XmlWriter) bir dosyaya yazmak gibi meta verileri kullanabilirsiniz.

Örnek

Aşağıda, bu örneğin tam kod listesi verilmiştir.

using System;
using System.ServiceModel;
using System.ServiceModel.Description;

namespace WsdlExporterSample
{
    class Program
    {
        static void Main(string[] args)
        {
            WsdlExporter exporter = new WsdlExporter();
            exporter.PolicyVersion = PolicyVersion.Policy15;

            ServiceEndpoint [] myServiceEndpoints = new ServiceEndpoint[2];
            ContractDescription myDescription = new ContractDescription ("myContract");
            myServiceEndpoints[0] = new ServiceEndpoint(myDescription,new BasicHttpBinding(),new EndpointAddress("http://localhost/myservice"));
            myServiceEndpoints[1] = new ServiceEndpoint(myDescription,new BasicHttpBinding(),new EndpointAddress("http://localhost/myservice"));

            // Export all endpoints for each endpoint in collection.
            foreach (ServiceEndpoint endpoint in myServiceEndpoints)
            {
                exporter.ExportEndpoint(endpoint);
            }
            // If there are no errors, get the documents.
            MetadataSet metadataDocs = null;
            if (exporter.Errors.Count != 0)
            {
                metadataDocs = exporter.GetGeneratedMetadata();
            }
        }
    }
}
Imports System.ServiceModel
Imports System.ServiceModel.Description

Module Module1

    Sub Main()
        Dim exporter As New WsdlExporter()
        exporter.PolicyVersion = PolicyVersion.Policy15

        Dim myServiceEndpoints() As ServiceEndpoint = New ServiceEndpoint(1) {}
        Dim myDescription As New ContractDescription("myContract")
        myServiceEndpoints(0) = New ServiceEndpoint(myDescription, New BasicHttpBinding(), New EndpointAddress("http://localhost/myservice"))
        myServiceEndpoints(1) = New ServiceEndpoint(myDescription, New BasicHttpBinding(), New EndpointAddress("http://localhost/myservice"))

        'Export all endpoints for each endpoint in collection.
        For Each endpoint As ServiceEndpoint In myServiceEndpoints
            exporter.ExportEndpoint(endpoint)
        Next

        'If there are no errors, get the documents.
        Dim metadataDocs As MetadataSet
        metadataDocs = Nothing

        If (exporter.Errors.Count = 0) Then
            metadataDocs = exporter.GetGeneratedMetadata()
        End If
    End Sub

End Module

Kod Derleniyor

Program.cs başvuru System.ServiceModel.dll derlenirken.

Ayrıca bkz.