MetadataResolver.Resolve Method

Definition

Downloads and resolves a metadata address into the ServiceEndpoint objects for that service.

Overloads

Resolve(IEnumerable<ContractDescription>, EndpointAddress)

Resolves a metadata address into the ServiceEndpoint objects for the specified contracts using the specified metadata address.

Resolve(Type, EndpointAddress)

Downloads and resolves a metadata address into a collection of ServiceEndpoint objects for a specified contract at a specified address.

Resolve(IEnumerable<ContractDescription>, EndpointAddress, MetadataExchangeClient)

Resolves a metadata address into the ServiceEndpoint objects for the specified contracts using the specified metadata address and MetadataExchangeClient.

Resolve(IEnumerable<ContractDescription>, Uri, MetadataExchangeClientMode)

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

Resolve(Type, Uri, MetadataExchangeClientMode)

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

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

Resolves a metadata address into the ServiceEndpoint objects for the specified contracts using the specified address, transfer mode, and transfer client.

Remarks

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

For all synchronous and asynchronous Resolve methods, 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.

Resolve(IEnumerable<ContractDescription>, EndpointAddress)

Resolves a metadata address into the ServiceEndpoint objects for the specified contracts using the specified metadata address.

public:
 static System::ServiceModel::Description::ServiceEndpointCollection ^ Resolve(System::Collections::Generic::IEnumerable<System::ServiceModel::Description::ContractDescription ^> ^ contracts, System::ServiceModel::EndpointAddress ^ address);
public static System.ServiceModel.Description.ServiceEndpointCollection Resolve (System.Collections.Generic.IEnumerable<System.ServiceModel.Description.ContractDescription> contracts, System.ServiceModel.EndpointAddress address);
static member Resolve : seq<System.ServiceModel.Description.ContractDescription> * System.ServiceModel.EndpointAddress -> System.ServiceModel.Description.ServiceEndpointCollection
Public Shared Function Resolve (contracts As IEnumerable(Of ContractDescription), address As EndpointAddress) As ServiceEndpointCollection

Parameters

contracts
IEnumerable<ContractDescription>

The contracts for which to download and resolve metadata.

address
EndpointAddress

The metadata address.

Returns

A collection of ServiceEndpoint objects for the specified contract.

Exceptions

The address or contracts collection is null.

contracts is empty, at least one member of contracts is null, or contracts contains more than one contract with the same name and namespace.

Remarks

The default settings on the System.ServiceModel.Description.MetadataExchangeClient are used to retrieve the metadata and the default System.ServiceModel.Description.MetadataExchangeClientMode is MetadataExchangeClientMode.MetadataExchange.

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

Note

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.

Applies to

Resolve(Type, EndpointAddress)

Downloads and resolves a metadata address into a collection of ServiceEndpoint objects for a specified contract at a specified address.

public:
 static System::ServiceModel::Description::ServiceEndpointCollection ^ Resolve(Type ^ contract, System::ServiceModel::EndpointAddress ^ address);
public static System.ServiceModel.Description.ServiceEndpointCollection Resolve (Type contract, System.ServiceModel.EndpointAddress address);
static member Resolve : Type * System.ServiceModel.EndpointAddress -> System.ServiceModel.Description.ServiceEndpointCollection
Public Shared Function Resolve (contract As Type, address As EndpointAddress) As ServiceEndpointCollection

Parameters

contract
Type

The contracts for which to download and resolve metadata.

address
EndpointAddress

The metadata address.

Returns

A collection of ServiceEndpoint objects for the specified contract.

Exceptions

The address or the contract is null.

Examples

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

Remarks

Use the Resolve method to specify the contract and the metadata address to use when downloading and resolving metadata.

The default settings on the System.ServiceModel.Description.MetadataExchangeClient are used to retrieve the metadata and the default System.ServiceModel.Description.MetadataExchangeClientMode is MetadataExchangeClientMode.MetadataExchange.

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

Note

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.

This method requires that you specify a contract type. You can specify the contract by declaring the service interface in the client code or by using a WCF client generated by Svcutil.exe. If the interface changes (adding a new operation, for example) you must update the interface in the client code or generate a new WCF client. If you do not, an exception is thrown. For example, you have a service that implements a service contract called ICalculator that defines Add(), Sub(), Mult(), and Div(). You create a client application and generate WCF client. You then add a method to ICalculator called Echo(). If you then write an application that calls Resolve(Type, EndpointAddress) without generating a new WCF client you get the following exception.

Unhandled Exception: System.ServiceModel.Description.WsdlImporter+WsdlImportException: Cannot locate operation Echo in Contract ICalculator.

Applies to

Resolve(IEnumerable<ContractDescription>, EndpointAddress, MetadataExchangeClient)

Resolves a metadata address into the ServiceEndpoint objects for the specified contracts using the specified metadata address and MetadataExchangeClient.

public:
 static System::ServiceModel::Description::ServiceEndpointCollection ^ Resolve(System::Collections::Generic::IEnumerable<System::ServiceModel::Description::ContractDescription ^> ^ contracts, System::ServiceModel::EndpointAddress ^ address, System::ServiceModel::Description::MetadataExchangeClient ^ client);
public static System.ServiceModel.Description.ServiceEndpointCollection Resolve (System.Collections.Generic.IEnumerable<System.ServiceModel.Description.ContractDescription> contracts, System.ServiceModel.EndpointAddress address, System.ServiceModel.Description.MetadataExchangeClient client);
static member Resolve : seq<System.ServiceModel.Description.ContractDescription> * System.ServiceModel.EndpointAddress * System.ServiceModel.Description.MetadataExchangeClient -> System.ServiceModel.Description.ServiceEndpointCollection
Public Shared Function Resolve (contracts As IEnumerable(Of ContractDescription), address As EndpointAddress, client As MetadataExchangeClient) As ServiceEndpointCollection

Parameters

contracts
IEnumerable<ContractDescription>

The contracts for which to download and resolve metadata.

address
EndpointAddress

The metadata address.

client
MetadataExchangeClient

The MetadataExchangeClient used to retrieve the metadata.

Returns

A collection of ServiceEndpoint objects for the specified contract.

Exceptions

The address, contracts collection, or client is null.

contracts is empty, at least one member of contracts is null, or contracts contains more than one contract with the same name and namespace.

Remarks

The default System.ServiceModel.Description.MetadataExchangeClientMode is MetadataExchangeClientMode.MetadataExchange.

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

Note

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.

Applies to

Resolve(IEnumerable<ContractDescription>, Uri, MetadataExchangeClientMode)

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

public:
 static System::ServiceModel::Description::ServiceEndpointCollection ^ Resolve(System::Collections::Generic::IEnumerable<System::ServiceModel::Description::ContractDescription ^> ^ contracts, Uri ^ address, System::ServiceModel::Description::MetadataExchangeClientMode mode);
public static System.ServiceModel.Description.ServiceEndpointCollection Resolve (System.Collections.Generic.IEnumerable<System.ServiceModel.Description.ContractDescription> contracts, Uri address, System.ServiceModel.Description.MetadataExchangeClientMode mode);
static member Resolve : seq<System.ServiceModel.Description.ContractDescription> * Uri * System.ServiceModel.Description.MetadataExchangeClientMode -> System.ServiceModel.Description.ServiceEndpointCollection
Public Shared Function Resolve (contracts As IEnumerable(Of ContractDescription), address As Uri, mode As MetadataExchangeClientMode) As ServiceEndpointCollection

Parameters

contracts
IEnumerable<ContractDescription>

The contracts for which to download and resolve metadata.

address
Uri

The metadata address.

mode
MetadataExchangeClientMode

The mode of retrieval.

Returns

A collection of ServiceEndpoint objects for the specified contract.

Exceptions

The address or contracts collection is null.

contracts is empty, at least one member of contracts is null, or contracts contains more than one contract with the same name and namespace.

Remarks

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.

Note

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.

Applies to

Resolve(Type, Uri, MetadataExchangeClientMode)

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

public:
 static System::ServiceModel::Description::ServiceEndpointCollection ^ Resolve(Type ^ contract, Uri ^ address, System::ServiceModel::Description::MetadataExchangeClientMode mode);
public static System.ServiceModel.Description.ServiceEndpointCollection Resolve (Type contract, Uri address, System.ServiceModel.Description.MetadataExchangeClientMode mode);
static member Resolve : Type * Uri * System.ServiceModel.Description.MetadataExchangeClientMode -> System.ServiceModel.Description.ServiceEndpointCollection
Public Shared Function Resolve (contract As Type, address As Uri, mode As MetadataExchangeClientMode) As ServiceEndpointCollection

Parameters

contract
Type

The contract for which to download and resolve metadata.

address
Uri

The metadata address.

mode
MetadataExchangeClientMode

The mode of retrieval.

Returns

A collection of ServiceEndpoint objects for the specified contract.

Exceptions

The address or contract is null.

Examples

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

Remarks

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.

Note

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.

Applies to

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

Resolves a metadata address into the ServiceEndpoint objects for the specified contracts using the specified address, transfer mode, and transfer client.

public:
 static System::ServiceModel::Description::ServiceEndpointCollection ^ Resolve(System::Collections::Generic::IEnumerable<System::ServiceModel::Description::ContractDescription ^> ^ contracts, Uri ^ address, System::ServiceModel::Description::MetadataExchangeClientMode mode, System::ServiceModel::Description::MetadataExchangeClient ^ client);
public static System.ServiceModel.Description.ServiceEndpointCollection Resolve (System.Collections.Generic.IEnumerable<System.ServiceModel.Description.ContractDescription> contracts, Uri address, System.ServiceModel.Description.MetadataExchangeClientMode mode, System.ServiceModel.Description.MetadataExchangeClient client);
static member Resolve : seq<System.ServiceModel.Description.ContractDescription> * Uri * System.ServiceModel.Description.MetadataExchangeClientMode * System.ServiceModel.Description.MetadataExchangeClient -> System.ServiceModel.Description.ServiceEndpointCollection
Public Shared Function Resolve (contracts As IEnumerable(Of ContractDescription), address As Uri, mode As MetadataExchangeClientMode, client As MetadataExchangeClient) As ServiceEndpointCollection

Parameters

contracts
IEnumerable<ContractDescription>

The contracts for which to download and resolve metadata.

address
Uri

The metadata address.

mode
MetadataExchangeClientMode

The mode of retrieval.

client
MetadataExchangeClient

The MetadataExchangeClient used to retrieve the metadata.

Returns

A collection of ServiceEndpoint objects for the specified contract.

Exceptions

The address, contracts collection, or client is null.

contracts is empty, at least one member of contracts is null, or contracts contains more than one contract with the same name and namespace.

Remarks

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

Note

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.

Applies to