MetadataResolver 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
擷取及匯入做為 ServiceEndpoint 物件的中繼資料。
public ref class MetadataResolver abstract sealed
public static class MetadataResolver
type MetadataResolver = class
Public Class MetadataResolver
- 繼承
-
MetadataResolver
範例
下列程式碼範例會示範如何使用 MetadataResolver 類別,將中繼資料當做 ServiceEndpoint 物件集合傳回,接著用來連接至服務執行個體。
// 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();
}
}
下列程式碼範例會示範如何透過 HTTP GET 要求而非 WS-Transfer,使用 MetadataResolver 下載中繼資料並將中繼資料當做 ServiceEndpoint 物件集合傳回。
// 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();
}
}
備註
您可以使用 MetadataResolver 類別,快速地從中繼資料匯入服務的端點。 這個類別會下載中繼資料,並將它轉換為 ServiceEndpoint 物件。 若要下載中繼資料並處理該資訊以做為 System.ServiceModel.Description.MetadataSet,請參閱 System.ServiceModel.Description.MetadataExchangeClient。