MetadataResolver.Resolve 方法
定义
下载元数据地址并将其解析为该服务的 ServiceEndpoint 对象。Downloads and resolves a metadata address into the ServiceEndpoint objects for that service.
重载
| Resolve(IEnumerable<ContractDescription>, EndpointAddress) |
使用指定元数据地址,将元数据地址解析为指定协定的 ServiceEndpoint 对象。Resolves a metadata address into the ServiceEndpoint objects for the specified contracts using the specified metadata address. |
| Resolve(Type, EndpointAddress) |
下载元数据地址并将其解析为指定地址处的指定协定的 ServiceEndpoint 对象的集合。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) |
使用指定元数据地址和 ServiceEndpoint,将元数据地址解析为指定协定的 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) |
使用指定地址和传输模式,将元数据地址解析为指定协定的 ServiceEndpoint 对象。Resolves a metadata address into the ServiceEndpoint objects for the specified contracts using the specified address and transfer mode. |
| Resolve(Type, Uri, MetadataExchangeClientMode) |
使用指定地址和传输模式,将元数据地址解析为指定协定的 ServiceEndpoint 对象。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) |
使用指定地址、传输模式和传输客户端,将元数据地址解析为指定协定的 ServiceEndpoint 对象。Resolves a metadata address into the ServiceEndpoint objects for the specified contracts using the specified address, transfer mode, and transfer client. |
注解
若要下载元数据,而不是将信息解析为 ServiceEndpoint 对象,请直接使用 System.ServiceModel.Description.MetadataExchangeClient。To download metadata but not resolve the information into ServiceEndpoint objects, use the System.ServiceModel.Description.MetadataExchangeClient directly.
对于所有同步和异步 Resolve 方法,如果未导入终结点或没有与约定相匹配的终结点,则返回空集合。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)
使用指定元数据地址,将元数据地址解析为指定协定的 ServiceEndpoint 对象。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
参数
- contracts
- IEnumerable<ContractDescription>
要为其下载和解析元数据的协定。The contracts for which to download and resolve metadata.
- address
- EndpointAddress
元数据地址。The metadata address.
返回
指定协定的 ServiceEndpoint 对象的集合。A collection of ServiceEndpoint objects for the specified contract.
例外
地址或协定集合为 null。The address or contracts collection is null.
contracts 为空,contracts 的至少一个成员为 Null,或者 contracts 包含多个具有相同名称和命名空间的协定。contracts is empty, at least one member of contracts is null, or contracts contains more than one contract with the same name and namespace.
注解
System.ServiceModel.Description.MetadataExchangeClient 上的默认设置用于检索元数据,并且默认 System.ServiceModel.Description.MetadataExchangeClientMode 为 MetadataExchangeClientMode.MetadataExchange。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.
若要下载元数据,而不是将信息解析为 ServiceEndpoint 对象,请直接使用 System.ServiceModel.Description.MetadataExchangeClient。To download metadata but not resolve the information into ServiceEndpoint objects, use the System.ServiceModel.Description.MetadataExchangeClient directly.
备注
如果没有导入终结点或者没有与协定匹配的终结点,则返回一个空集合。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(Type, EndpointAddress)
下载元数据地址并将其解析为指定地址处的指定协定的 ServiceEndpoint 对象的集合。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
参数
- contract
- Type
要为其下载和解析元数据的协定。The contracts for which to download and resolve metadata.
- address
- EndpointAddress
元数据地址。The metadata address.
返回
指定协定的 ServiceEndpoint 对象的集合。A collection of ServiceEndpoint objects for the specified contract.
例外
地址或协定为 null。The address or the contract is null.
示例
下面的代码示例演示如何使用 MetadataResolver 类返回作为 ServiceEndpoint 对象的集合的元数据,稍后这些对象将用于连接服务实例。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();
}
}
注解
使用 Resolve 方法可指定下载和解析元数据时要使用的协定和元数据地址。Use the Resolve method to specify the contract and the metadata address to use when downloading and resolving metadata.
System.ServiceModel.Description.MetadataExchangeClient 上的默认设置用于检索元数据,并且默认 System.ServiceModel.Description.MetadataExchangeClientMode 为 MetadataExchangeClientMode.MetadataExchange。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.
若要下载元数据,而不是将信息解析为 ServiceEndpoint 对象,请直接使用 System.ServiceModel.Description.MetadataExchangeClient。To download metadata but not resolve the information into ServiceEndpoint objects, use the System.ServiceModel.Description.MetadataExchangeClient directly.
备注
如果没有导入终结点或者没有与协定匹配的终结点,则返回一个空集合。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. 可以通过在客户端代码中声明服务接口或使用由 Svcutil.exe 生成的 WCF 客户端来指定协定。You can specify the contract by declaring the service interface in the client code or by using a WCF client generated by Svcutil.exe. 如果接口更改 (添加新操作,例如) 必须在客户端代码中更新该接口或生成新的 WCF 客户端。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. 例如,您有一个可实现称为 ICalculator 的服务协定的服务,该协定可定义 Add()、Sub()、Mult() 和 Div()。For example, you have a service that implements a service contract called ICalculator that defines Add(), Sub(), Mult(), and Div(). 您将创建一个客户端应用程序并生成 WCF 客户端。You create a client application and generate WCF client. 然后您向 ICalculator 添加了一个方法,称为 Echo()。You then add a method to ICalculator called Echo(). 如果随后编写一个调用 Resolve(Type, EndpointAddress) 而不生成新 WCF 客户端的应用程序,则会出现以下异常。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.Unhandled Exception: System.ServiceModel.Description.WsdlImporter+WsdlImportException: Cannot locate operation Echo in Contract ICalculator.
适用于
Resolve(IEnumerable<ContractDescription>, EndpointAddress, MetadataExchangeClient)
使用指定元数据地址和 ServiceEndpoint,将元数据地址解析为指定协定的 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
参数
- contracts
- IEnumerable<ContractDescription>
要为其下载和解析元数据的协定。The contracts for which to download and resolve metadata.
- address
- EndpointAddress
元数据地址。The metadata address.
- client
- MetadataExchangeClient
用于解析元数据的 MetadataExchangeClient。The MetadataExchangeClient used to retrieve the metadata.
返回
指定协定的 ServiceEndpoint 对象的集合。A collection of ServiceEndpoint objects for the specified contract.
例外
地址、协定集合或客户端为 null。The address, contracts collection, or client is null.
contracts 为空,contracts 的至少一个成员为 Null,或者 contracts 包含多个具有相同名称和命名空间的协定。contracts is empty, at least one member of contracts is null, or contracts contains more than one contract with the same name and namespace.
注解
默认 System.ServiceModel.Description.MetadataExchangeClientMode 为 MetadataExchangeClientMode.MetadataExchange。The default System.ServiceModel.Description.MetadataExchangeClientMode is MetadataExchangeClientMode.MetadataExchange.
若要下载元数据,而不是将信息解析为 ServiceEndpoint 对象,请直接使用 System.ServiceModel.Description.MetadataExchangeClient。To download metadata but not resolve the information into ServiceEndpoint objects, use the System.ServiceModel.Description.MetadataExchangeClient directly.
备注
如果没有导入终结点或者没有与协定匹配的终结点,则返回一个空集合。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>, Uri, MetadataExchangeClientMode)
使用指定地址和传输模式,将元数据地址解析为指定协定的 ServiceEndpoint 对象。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
参数
- contracts
- IEnumerable<ContractDescription>
要为其下载和解析元数据的协定。The contracts for which to download and resolve metadata.
- address
- Uri
元数据地址。The metadata address.
检索的模式。The mode of retrieval.
返回
指定协定的 ServiceEndpoint 对象的集合。A collection of ServiceEndpoint objects for the specified contract.
例外
地址或协定集合为 null。The address or contracts collection is null.
contracts 为空,contracts 的至少一个成员为 Null,或者 contracts 包含多个具有相同名称和命名空间的协定。contracts is empty, at least one member of contracts is null, or contracts contains more than one contract with the same name and namespace.
注解
System.ServiceModel.Description.MetadataExchangeClient 上的默认设置用于检索元数据。The default settings on the System.ServiceModel.Description.MetadataExchangeClient are used to retrieve the metadata.
若要下载元数据,而不是将信息解析为 ServiceEndpoint 对象,请直接使用 System.ServiceModel.Description.MetadataExchangeClient。To download metadata but not resolve the information into ServiceEndpoint objects, use the System.ServiceModel.Description.MetadataExchangeClient directly.
备注
如果没有导入终结点或者没有与协定匹配的终结点,则返回一个空集合。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(Type, Uri, MetadataExchangeClientMode)
使用指定地址和传输模式,将元数据地址解析为指定协定的 ServiceEndpoint 对象。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
参数
- contract
- Type
要为其下载和解析元数据的协定。The contract for which to download and resolve metadata.
- address
- Uri
元数据地址。The metadata address.
检索的模式。The mode of retrieval.
返回
指定协定的 ServiceEndpoint 对象的集合。A collection of ServiceEndpoint objects for the specified contract.
例外
地址或协定为 null。The address or contract is null.
示例
下面的代码示例演示如何使用 MetadataResolver 下载和返回作为 ServiceEndpoint 对象的集合的元数据,这些对象使用 HTTP GET 请求而不是 WS-Transfer。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();
}
}
注解
使用 Resolve 方法可指定协定、地址和要使用的下载机制。Use the Resolve method to specify a contract, and address, and the download mechanism to use.
System.ServiceModel.Description.MetadataExchangeClient 上的默认设置用于检索元数据。The default settings on the System.ServiceModel.Description.MetadataExchangeClient are used to retrieve the metadata.
若要下载元数据,而不是将信息解析为 ServiceEndpoint 对象,请直接使用 System.ServiceModel.Description.MetadataExchangeClient。To download metadata but not resolve the information into ServiceEndpoint objects, use the System.ServiceModel.Description.MetadataExchangeClient directly.
备注
如果没有导入终结点或者没有与协定匹配的终结点,则返回一个空集合。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>, Uri, MetadataExchangeClientMode, MetadataExchangeClient)
使用指定地址、传输模式和传输客户端,将元数据地址解析为指定协定的 ServiceEndpoint 对象。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
参数
- contracts
- IEnumerable<ContractDescription>
要为其下载和解析元数据的协定。The contracts for which to download and resolve metadata.
- address
- Uri
元数据地址。The metadata address.
检索的模式。The mode of retrieval.
- client
- MetadataExchangeClient
用于解析元数据的 MetadataExchangeClient。The MetadataExchangeClient used to retrieve the metadata.
返回
指定协定的 ServiceEndpoint 对象的集合。A collection of ServiceEndpoint objects for the specified contract.
例外
地址、协定集合或客户端为 null。The address, contracts collection, or client is null.
contracts 为空,contracts 的至少一个成员为 Null,或者 contracts 包含多个具有相同名称和命名空间的协定。contracts is empty, at least one member of contracts is null, or contracts contains more than one contract with the same name and namespace.
注解
若要下载元数据,而不是将信息解析为 ServiceEndpoint 对象,请直接使用 System.ServiceModel.Description.MetadataExchangeClient。To download metadata but not resolve the information into ServiceEndpoint objects, use the System.ServiceModel.Description.MetadataExchangeClient directly.
备注
如果没有导入终结点或者没有与协定匹配的终结点,则返回一个空集合。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.