WsdlExporter.GetGeneratedMetadata 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回所生成的 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 方法,从 MetadataSection 所调用的 ServiceEndpoint 对象集合中的终结点生成一组 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、ExportContract 或 ExportEndpoint 调用所生成的结果,使用 ExportEndpoints 属性可获取这些结果的全部元数据的集合。
建议您在检索元数据前,先检查基本 Errors 属性,以确定是否有错误发生。