MetadataResolver::Resolve Method (Type^, EndpointAddress^)
Downloads and resolves a metadata address into a collection of ServiceEndpoint objects for a specified contract at a specified address.
Assembly: System.ServiceModel (in System.ServiceModel.dll)
public: static ServiceEndpointCollection^ Resolve( Type^ contract, EndpointAddress^ address )
Parameters
- contract
-
Type:
System::Type^
The contracts for which to download and resolve metadata.
- address
-
Type:
System.ServiceModel::EndpointAddress^
The metadata address.
Return Value
Type: System.ServiceModel.Description::ServiceEndpointCollection^A collection of ServiceEndpoint objects for the specified contract.
| Exception | Condition |
|---|---|
| ArgumentNullException | The address or the contract is null. |
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.
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(); } }
Available since 3.0
