Export (0) Print
Expand All

MetadataResolver.Resolve Method (Type, Uri, MetadataExchangeClientMode)

Resolves a metadata address into the ServiceEndpoint objects for the specified contract using the specified address and transfer mode.

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

public static ServiceEndpointCollection Resolve(
	Type contract,
	Uri address,
	MetadataExchangeClientMode mode
)

Parameters

contract
Type: System.Type

The contract for which to download and resolve metadata.

address
Type: System.Uri

The metadata address.

mode
Type: System.ServiceModel.Description.MetadataExchangeClientMode

The mode of retrieval.

Return Value

Type: System.ServiceModel.Description.ServiceEndpointCollection
A collection of ServiceEndpoint objects for the specified contract.

ExceptionCondition
ArgumentNullException

The address or contract is null.

Use the Resolve method to specify a contract, and address, and the download mechanism to use.

The default settings on the System.ServiceModel.Description.MetadataExchangeClient are used to retrieve the metadata.

To download metadata but not resolve the information into ServiceEndpoint objects, use the System.ServiceModel.Description.MetadataExchangeClient directly.

NoteNote

An empty collection is returned if no endpoints were imported or if no endpoints matched the contract. If an empty collection is returned, a warning trace is written.

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

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft