다음을 통해 공유


방법: 서비스 엔드포인트에서 메타데이터 내보내기

이 항목에서는 서비스 엔드포인트로부터 메타데이터를 내보내는 방법에 대해 설명합니다.

서비스 엔드포인트에서 메타데이터를 내보내려면

  1. 새 Visual Studio Console App Project를 만듭니다. 다음 단계에 표시된 코드를 생성된 Program.cs 파일의 main() 메서드에 추가합니다.

  2. WsdlExporter을 만듭니다.

    WsdlExporter exporter = new WsdlExporter();
    
    Dim exporter As New WsdlExporter()
    
  3. PolicyVersion 속성을 PolicyVersion 열거형의 값 중 하나로 설정합니다. 샘플에서는 값을 WS-Policy 1.5에 해당되는 Policy15로 설정합니다.

    exporter.PolicyVersion = PolicyVersion.Policy15;
    
    exporter.PolicyVersion = PolicyVersion.Policy15
    
  4. ServiceEndpoint 개체의 배열을 만듭니다.

    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. 각 서비스 엔드포인트의 메타데이터를 내보냅니다.

    // 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. 내보내기 프로세스 중에 오류가 발생하지 않았는지 확인하고 메타데이터를 검색합니다.

    // 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. 이제 WriteTo(XmlWriter) 메서드를 호출하여 파일에 쓰는 등의 방식으로 메타데이터를 사용할 수 있습니다.

예시

다음은 이 예제에 해당되는 전체 코드 목록입니다.

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

코드 컴파일

Program.cs를 컴파일할 때에는 System.ServiceModel.dll을 참조하세요.

참고 항목