MetadataResolver.Resolve 方法

定義

下載中繼資料位址,並解析成該服務的 ServiceEndpoint 物件。

多載

Resolve(IEnumerable<ContractDescription>, EndpointAddress)

使用指定的中繼資料位址,將中繼資料位址解析成指定之合約的 ServiceEndpoint 物件。

Resolve(Type, EndpointAddress)

針對指定位址的指定合約下載中繼資料位址,並解析成 ServiceEndpoint 物件集合。

Resolve(IEnumerable<ContractDescription>, EndpointAddress, MetadataExchangeClient)

使用指定的中繼資料位址和 ServiceEndpoint,將中繼資料位址解析成指定之合約的 MetadataExchangeClient 物件。

Resolve(IEnumerable<ContractDescription>, Uri, MetadataExchangeClientMode)

使用指定的位址和傳輸模式,將中繼資料位址解析成指定之合約的 ServiceEndpoint 物件。

Resolve(Type, Uri, MetadataExchangeClientMode)

使用指定的位址和傳輸模式,將中繼資料位址解析成指定之合約的 ServiceEndpoint 物件。

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

使用指定的位址、傳輸模式和傳輸用戶端,將中繼資料位址解析成指定之合約的 ServiceEndpoint 物件。

備註

若要下載中繼資料,但不想將資訊解析成 ServiceEndpoint 物件,請直接使用 System.ServiceModel.Description.MetadataExchangeClient

針對所有同步和非同步 Resolve 方法,如果沒有匯入任何端點或者沒有符合合約的端點,則會傳回空集合。 如果傳回空集合,則會寫入警告追蹤。

Resolve(IEnumerable<ContractDescription>, EndpointAddress)

使用指定的中繼資料位址,將中繼資料位址解析成指定之合約的 ServiceEndpoint 物件。

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>

要下載並解析其中繼資料的合約。

address
EndpointAddress

中繼資料的位址。

傳回

ServiceEndpointCollection

指定之合約的 ServiceEndpoint 物件集合。

例外狀況

位址或合約集合為 null

contracts 為空的、至少 contracts 的其中一個成員為 null,或者 contracts 包含一個以上同名且命名空間相同的合約。

備註

會使用 System.ServiceModel.Description.MetadataExchangeClient 上的預設值以擷取中繼資料,而預設的 System.ServiceModel.Description.MetadataExchangeClientMode 則為 MetadataExchangeClientMode.MetadataExchange

若要下載中繼資料,但不想將資訊解析成 ServiceEndpoint 物件,請直接使用 System.ServiceModel.Description.MetadataExchangeClient

注意

如果沒有匯入端點,或者如果沒有符合合約的端點,則會傳回空集合。 如果傳回空集合,則會寫入警告追蹤。

適用於

Resolve(Type, EndpointAddress)

針對指定位址的指定合約下載中繼資料位址,並解析成 ServiceEndpoint 物件集合。

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

要下載並解析其中繼資料的合約。

address
EndpointAddress

中繼資料的位址。

傳回

ServiceEndpointCollection

指定之合約的 ServiceEndpoint 物件集合。

例外狀況

位址或合約為 null

範例

下列程式碼範例會示範如何使用 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();
    }
}

備註

您可以使用 Resolve 方法,指定下載及解析中繼資料時要使用的合約和中繼資料位址。

會使用 System.ServiceModel.Description.MetadataExchangeClient 上的預設值以擷取中繼資料,而預設的 System.ServiceModel.Description.MetadataExchangeClientMode 則為 MetadataExchangeClientMode.MetadataExchange

若要下載中繼資料,但不想將資訊解析成 ServiceEndpoint 物件,請直接使用 System.ServiceModel.Description.MetadataExchangeClient

注意

如果沒有匯入端點,或者如果沒有符合合約的端點,則會傳回空集合。 如果傳回空集合,則會寫入警告追蹤。

使用這個方法時,您需要指定合約類型。 您可以在用戶端程式代碼中宣告服務介面,或使用由 Svcutil.exe 產生的 WCF 用戶端來指定合約。 如果介面變更 (新增作業,例如) 您必須更新用戶端程式代碼中的介面,或產生新的 WCF 用戶端。 如果沒有這樣做,則會擲回例外狀況。 例如,您的服務會實作名為 ICalculator (定義 Add()、Sub()、Mult() 和 Div()) 的服務合約。 您可以建立用戶端應用程式並產生 WCF 用戶端。 接著將名為 Echo() 的方法加入至 ICalculator。 如果您接著撰寫呼叫的應用程式 Resolve(Type, EndpointAddress) ,而不產生新的 WCF 用戶端,您會收到下列例外狀況。

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

適用於

Resolve(IEnumerable<ContractDescription>, EndpointAddress, MetadataExchangeClient)

使用指定的中繼資料位址和 ServiceEndpoint,將中繼資料位址解析成指定之合約的 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>

要下載並解析其中繼資料的合約。

address
EndpointAddress

中繼資料的位址。

client
MetadataExchangeClient

用來擷取中繼資料的 MetadataExchangeClient

傳回

ServiceEndpointCollection

指定之合約的 ServiceEndpoint 物件集合。

例外狀況

位址、合約集合或用戶端為 null

contracts 為空的、至少 contracts 的其中一個成員為 null,或者 contracts 包含一個以上同名且命名空間相同的合約。

備註

預設 System.ServiceModel.Description.MetadataExchangeClientModeMetadataExchangeClientMode.MetadataExchange

若要下載中繼資料,但不想將資訊解析成 ServiceEndpoint 物件,請直接使用 System.ServiceModel.Description.MetadataExchangeClient

注意

如果沒有匯入端點,或者如果沒有符合合約的端點,則會傳回空集合。 如果傳回空集合,則會寫入警告追蹤。

適用於

Resolve(IEnumerable<ContractDescription>, Uri, MetadataExchangeClientMode)

使用指定的位址和傳輸模式,將中繼資料位址解析成指定之合約的 ServiceEndpoint 物件。

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>

要下載並解析其中繼資料的合約。

address
Uri

中繼資料的位址。

mode
MetadataExchangeClientMode

擷取模式。

傳回

ServiceEndpointCollection

指定之合約的 ServiceEndpoint 物件集合。

例外狀況

位址或合約集合為 null

contracts 為空的、至少 contracts 的其中一個成員為 null,或者 contracts 包含一個以上同名且命名空間相同的合約。

備註

System.ServiceModel.Description.MetadataExchangeClient 的預設值是用來擷取中繼資料。

若要下載中繼資料,但不想將資訊解析成 ServiceEndpoint 物件,請直接使用 System.ServiceModel.Description.MetadataExchangeClient

注意

如果沒有匯入端點,或者如果沒有符合合約的端點,則會傳回空集合。 如果傳回空集合,則會寫入警告追蹤。

適用於

Resolve(Type, Uri, MetadataExchangeClientMode)

使用指定的位址和傳輸模式,將中繼資料位址解析成指定之合約的 ServiceEndpoint 物件。

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

要下載並解析其中繼資料的合約。

address
Uri

中繼資料的位址。

mode
MetadataExchangeClientMode

擷取模式。

傳回

ServiceEndpointCollection

指定之合約的 ServiceEndpoint 物件集合。

例外狀況

位址或合約為 null

範例

下列程式碼範例會示範如何透過 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();
    }
}

備註

您可以使用 Resolve 方法指定合約、位址和要使用的下載機制。

System.ServiceModel.Description.MetadataExchangeClient 的預設值是用來擷取中繼資料。

若要下載中繼資料,但不想將資訊解析成 ServiceEndpoint 物件,請直接使用 System.ServiceModel.Description.MetadataExchangeClient

注意

如果沒有匯入端點,或者如果沒有符合合約的端點,則會傳回空集合。 如果傳回空集合,則會寫入警告追蹤。

適用於

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

使用指定的位址、傳輸模式和傳輸用戶端,將中繼資料位址解析成指定之合約的 ServiceEndpoint 物件。

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>

要下載並解析其中繼資料的合約。

address
Uri

中繼資料的位址。

mode
MetadataExchangeClientMode

擷取模式。

client
MetadataExchangeClient

用來擷取中繼資料的 MetadataExchangeClient

傳回

ServiceEndpointCollection

指定之合約的 ServiceEndpoint 物件集合。

例外狀況

位址、合約集合或用戶端為 null

contracts 為空的、至少 contracts 的其中一個成員為 null,或者 contracts 包含一個以上同名且命名空間相同的合約。

備註

若要下載中繼資料,但不想將資訊解析成 ServiceEndpoint 物件,請直接使用 System.ServiceModel.Description.MetadataExchangeClient

注意

如果沒有匯入端點,或者如果沒有符合合約的端點,則會傳回空集合。 如果傳回空集合,則會寫入警告追蹤。

適用於