Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

MetadataResolver Class

Retrieves and imports metadata as ServiceEndpoint objects.

Namespace: System.ServiceModel.Description
Assembly: System.ServiceModel (in system.servicemodel.dll)

public static class MetadataResolver
public final class MetadataResolver
public final class MetadataResolver
Not applicable.

Use the MetadataResolver class to quickly import endpoints for a service from metadata. This class downloads and converts metadata into ServiceEndpoint objects. To download metadata and process that information as a System.ServiceModel.Description.MetadataSet, see System.ServiceModel.Description.MetadataExchangeClient.

The following code example shows the use of the MetadataResolver class to return metadata as a collection of ServiceEndpoint objects that are then used to connect to a service instance.

// 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();
  }
}

The following code example shows the use of the MetadataResolver to download and return metadata as a collection of ServiceEndpoint objects using an HTTP GET request rather than 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();
  }
}

System.Object
  System.ServiceModel.Description.MetadataResolver
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.