共用方式為


WsdlExporter.GetGeneratedMetadata 方法

定義

傳回產生的 MetadataSection 物件的可列舉集合。

public:
 override System::ServiceModel::Description::MetadataSet ^ GetGeneratedMetadata();
public override System.ServiceModel.Description.MetadataSet GetGeneratedMetadata ();
override this.GetGeneratedMetadata : unit -> System.ServiceModel.Description.MetadataSet
Public Overrides Function GetGeneratedMetadata () As MetadataSet

傳回

產生的 MetadataSection 物件的可列舉集合,表示呼叫 ExportContract(ContractDescription)ExportEndpoint(ServiceEndpoint)ExportEndpoints(IEnumerable<ServiceEndpoint>, XmlQualifiedName) 之後所產生的中繼資料。

範例

下列程式碼範例會示範如何使用 ExportEndpoint 方法,從稱為 MetadataSectionServiceEndpoint 物件集合中的端點產生一組 myServiceEndpoints 物件。

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

備註

您可以使用 GetGeneratedMetadata 屬性,取得在呼叫 ExportContractExportEndpointExportEndpoints 任何次數之後所產生的所有中繼資料的集合。

建議您檢查基底 Errors 屬性,以判斷在您擷取中繼資料之前是否發生任何的錯誤。

適用於