MetadataResolver 类

定义

检索和导入元数据作为 ServiceEndpoint 对象。

public ref class MetadataResolver abstract sealed
public static class MetadataResolver
type MetadataResolver = class
Public Class MetadataResolver
继承
MetadataResolver

示例

下面的代码示例演示如何使用 MetadataResolver 类将元数据作为对象集合 ServiceEndpoint 返回,这些对象随后用于连接到服务实例。

// Get the endpoints for such a service
ServiceEndpointCollection endpoints = MetadataResolver.Resolve(typeof(SampleServiceClient), metaAddress);
Console.WriteLine("Trying all available WS-Transfer metadata endpoints...");

foreach (ServiceEndpoint point in endpoints)
{
    if (point != null)
    {
        // Create a new wcfClient using retrieved endpoints.
        wcfClient = new SampleServiceClient(point.Binding, point.Address);
        Console.WriteLine(
          wcfClient.SampleMethod("Client used the "
          + point.Address.ToString()
          + " address.")
        );
        wcfClient.Close();
    }
}

下面的代码示例演示如何使用 MetadataResolver HTTP GET 请求(而不是 WS-Transfer)将元数据下载和返回为对象的集合 ServiceEndpoint

// Get the endpoints for such a service using Http/Get request
endpoints = MetadataResolver.Resolve(typeof(SampleServiceClient), httpGetMetaAddress.Uri, MetadataExchangeClientMode.HttpGet);
Client.WriteParameters(endpoints);
ISampleService serviceChannel;
Console.WriteLine(
  "\r\nTrying all endpoints from HTTP/Get and with direct service channels...");

foreach (ServiceEndpoint point in endpoints)
{
    if (point != null)
    {
        ChannelFactory<ISampleService> factory = new ChannelFactory<ISampleService>(point.Binding);
        factory.Endpoint.Address = point.Address;
        serviceChannel = factory.CreateChannel();
        Console.WriteLine("Client used the " + point.Address.ToString() + " address.");
        Console.WriteLine(
          serviceChannel.SampleMethod(
            "Client used the " + point.Address.ToString() + " address."
          )
        );
        factory.Close();
    }
}

注解

使用 MetadataResolver 类从元数据快速导入服务的终结点。 此类将下载元数据并将其转换为 ServiceEndpoint 对象。 若要下载元数据并处理该信息, System.ServiceModel.Description.MetadataSet请参阅 System.ServiceModel.Description.MetadataExchangeClient

方法

名称 说明
BeginResolve(IEnumerable<ContractDescription>, EndpointAddress, AsyncCallback, Object)

开始一个异步调用,该调用使用指定的地址和异步状态和委托将元数据地址解析为 ServiceEndpoint 指定协定的对象。

BeginResolve(IEnumerable<ContractDescription>, EndpointAddress, MetadataExchangeClient, AsyncCallback, Object)

开始一个异步调用,该调用使用指定的地址、ServiceEndpoint异步状态和委托将元数据地址解析为MetadataExchangeClient指定协定的对象。

BeginResolve(IEnumerable<ContractDescription>, Uri, MetadataExchangeClientMode, AsyncCallback, Object)

开始一个异步调用,该调用使用指定的地址、值、ServiceEndpoint异步状态和委托将元数据地址解析为MetadataExchangeClientMode指定协定的对象。

BeginResolve(IEnumerable<ContractDescription>, Uri, MetadataExchangeClientMode, MetadataExchangeClient, AsyncCallback, Object)

开始一个异步调用,该调用使用指定的地址、ServiceEndpointMetadataExchangeClient异步状态和委托将元数据地址解析为MetadataExchangeClientMode指定协定的对象。

BeginResolve(Type, EndpointAddress, AsyncCallback, Object)

开始一个异步调用,该调用使用指定的地址和异步状态和委托将元数据地址解析为 ServiceEndpoint 指定协定的对象。

BeginResolve(Type, Uri, MetadataExchangeClientMode, AsyncCallback, Object)

开始一个异步调用,该调用使用指定的地址、ServiceEndpoint异步状态和委托将元数据地址解析为MetadataExchangeClientMode指定协定的对象。

EndResolve(IAsyncResult)

完成异步调用,将元数据解析为终结点集合。

Resolve(IEnumerable<ContractDescription>, EndpointAddress, MetadataExchangeClient)

使用指定的元数据地址和指定的元数据地址ServiceEndpoint将元数据地址解析为MetadataExchangeClient指定协定的对象。

Resolve(IEnumerable<ContractDescription>, EndpointAddress)

使用指定的元数据地址将元数据地址解析为 ServiceEndpoint 指定协定的对象。

Resolve(IEnumerable<ContractDescription>, Uri, MetadataExchangeClientMode, MetadataExchangeClient)

使用指定的地址、传输模式和传输客户端将元数据地址解析为 ServiceEndpoint 指定协定的对象。

Resolve(IEnumerable<ContractDescription>, Uri, MetadataExchangeClientMode)

使用指定的地址和传输模式将元数据地址解析为 ServiceEndpoint 指定协定的对象。

Resolve(Type, EndpointAddress)

下载元数据地址并将其解析为指定地址处指定协定的对象集合 ServiceEndpoint

Resolve(Type, Uri, MetadataExchangeClientMode)

使用指定的地址和传输模式将元数据地址解析为 ServiceEndpoint 指定协定的对象。

适用于