MetadataResolver 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将元数据作为 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 下载和返回作为 ServiceEndpoint 对象的集合的元数据,这些对象使用 HTTP GET 请求而不是 WS-Transfer。
// 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。