HostNameComparisonMode 列舉

定義

指定當把傳入訊息分派給服務端點時,在 URI 比較中使用主機名稱的方式。Specifies how the host name should be used in URI comparisons when dispatching an incoming message to a service endpoint.

public enum class HostNameComparisonMode
public enum HostNameComparisonMode
type HostNameComparisonMode = 
Public Enum HostNameComparisonMode
繼承
HostNameComparisonMode

欄位

Exact 1

分派傳入訊息給此端點時使用主機名稱 (若沒有找到強式符合)。Uses the hostname when dispatching incoming messages to this endpoint, if no strong match was found.

StrongWildcard 0

分派傳入訊息給此端點時忽略主機名稱。Ignores the hostname when dispatching incoming messages to this endpoint. 這是預設值。This is the default value.

WeakWildcard 2

若沒有找到強式或完全符合,比對時便忽略主機名稱。If no strong or exact match was found, ignores the hostname when matching.

範例

以下是如何在服務端設定檔中設定 StrongWildcard 值的範例。The following is an example of how to set StrongWildcard value in a service side configuration file.

以下是採用前述組態檔的基本服務與用戶端。Here is a basic service and client that use the preceding configuration file.

[ServiceContract()]
public interface ISayHello
{
    [OperationContract()]
    string SayHello();
}

public class HelloService : ISayHello
{
    public string SayHello()
    {
        return "Hello, WCF!";
    }
}
// Open up a channel factory on a client application.
ChannelFactory<ISayHello> factory = new ChannelFactory<ISayHello>("BasicHttpBinding_ISayHello");

// Both of these contracts work (provided both hostnames are valid) because
// the binding configuration is set to hostNameComparisonMode="StrongWildcard".

ISayHello channel = factory.CreateChannel(new EndpointAddress("http://localhost:8000/UESamples/HelloService"));
ISayHello channel2 = factory.CreateChannel(new EndpointAddress("http://machineName/UESamples/HelloService"));

Console.WriteLine(channel.SayHello());

Console.WriteLine();
Console.WriteLine("Press <ENTER> to terminate client.");
Console.ReadLine();

備註

此值用來指定當分派傳入訊息時,傳輸 (如 HTTP、Net.Tcp 與 Net.Pipe) 所用的 URI 符合規則。The value is used to specify the URI matching rules used by transports such as HTTP, Net.Tcp, and Net.Pipe when dispatching incoming messages. 使用前述傳輸之一 (如 HostNameComparisonMode) 以及相對應的 BasicHttpBinding 屬性,來設定標準繫結的 HostNameComparisonMode 值。Configure the value of the HostNameComparisonMode for a standard binding using one of the preceding transports, such as BasicHttpBinding, using the corresponding HostNameComparisonMode property. 使用前述傳輸之一 (如 HostNameComparisonMode) 以及相對應的 HttpTransportBindingElement 屬性,來設定繫結項目的 HostNameComparisonMode 值。Configure the value of the HostNameComparisonMode for a binding element using one of the preceding transports, such as HttpTransportBindingElement, using the corresponding HostNameComparisonMode property.

每個 HostNameComparisonMode 的值都對應到特定型別的符合規則。Each value of the HostNameComparisonMode corresponds to a specific type of matching rule. 符合規則的採用順序必定如下︰The sequence of matching rules attempted is always ordered as follows:

  1. StrongWildcardStrongWildcard

  2. ExactExact

  3. WeakWildcardWeakWildcard

第一個值(StrongWildcard)會在比對時忽略主機名稱,而且它會採用三個不同比對模式的最高優先順序。The first value, StrongWildcard, ignores the host name when matching and it takes the highest precedence of the three different matching modes. 這是 WCF 系統提供之系結或繫結項目的預設值。It is the default value for a WCF system-provided binding or binding element. 這表示可以用任何有效的主機名稱,來找到服務端點。This indicates that a service endpoint can be reached using any valid host name. 例如,如果 MyService 是使用 http://localhost/MyService 裝載,仍然可以使用, http://www.adatum.com/MyService 因為會忽略(可能是有效的)主機名稱 "adatum.com"。For example, if MyService is hosted using http://localhost/MyService, it is still reachable using http://www.adatum.com/MyService because the (presumably valid) host name, "adatum.com", is ignored. 注意,這裡的連接埠亦是萬用字元。Note that the port is a wildcard here as well.

如果找不到強式比對,第二個值 Exact 會要求以指定的 URI (包括主機名稱)找到完全相符的。The second value, Exact, requires that an exact match is found with the URI specified, including the hostname, if no strong match is found. 例如,此模式不會比較主機簡稱與完整網域名稱是否等價。This mode, for example, does not perform equivalence between short hostnames and fully-qualified domain names. 如此一來,若多個主機都指派了同一個 IP 位址,便可在案例中將主機名稱做為符合準則,就能將不同服務裝載在同一台電腦上,並擁有不同的端點。This allows hostnames to be used as match criteria in the scenarios where multiple hosts are assigned a single IP address and it enables different services to be hosted on the same machine with distinct endpoints. 注意,這裡的連接埠亦是萬用字元。Note that the port is a wildcard here as well.

如果找不到強式或完全相符專案,則第三個值 WeakWildcard 會忽略主機名稱。The third value, WeakWildcard, matches by ignoring the hostname if no strong or exact match was found. 除了比對順序之外,此行為與 StrongWildcard 的行為相同:它會在嘗試強式和完全系結之後執行。The behavior is the same as for StrongWildcard other than the order of matching: it runs after the strong and exact bindings have been tried.

注意

若在 Internet Information Services (IIS) 或 Windows Process Activation Service (WAS) 裝載環境內使用,這些值便沒有效用。These values have no effect when used inside of the Internet Information Services (IIS) or Windows Process Activation Service (WAS) hosting environment. 在這些情況下,WCF 會使用裝載 WCF 服務的 IIS 網站所提供的任何主機名稱比較模式。In those cases, WCF uses whatever hostname comparison mode is provided by the IIS Web Site hosting the WCF services.

適用於