HostNameComparisonMode HostNameComparisonMode HostNameComparisonMode HostNameComparisonMode Enum

定义

Specifies how the host name should be used in URI comparisons when dispatching an incoming message to a service endpoint.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
继承
HostNameComparisonModeHostNameComparisonModeHostNameComparisonModeHostNameComparisonMode

字段

Exact Exact Exact Exact 1

Uses the hostname when dispatching incoming messages to this endpoint, if no strong match was found.Uses the hostname when dispatching incoming messages to this endpoint, if no strong match was found.

StrongWildcard StrongWildcard StrongWildcard StrongWildcard 0

Ignores the hostname when dispatching incoming messages to this endpoint.Ignores the hostname when dispatching incoming messages to this endpoint. This is the default value.This is the default value.

WeakWildcard WeakWildcard WeakWildcard WeakWildcard 2

If no strong or exact match was found, ignores the hostname when matching.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.

第二个值,精确、 需要完全匹配已找到具有 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 信息服务 (IIS) 或 Windows 进程激活服务 (WAS) 宿主环境中使用时无效。These values have no effect when used inside of the Internet Information Services (IIS) or Windows Process Activation Service (WAS) hosting environment. 在这些情况下,WCF 使用任何主机名比较模式提供由 IIS 网站中承载 WCF 服务。In those cases, WCF uses whatever hostname comparison mode is provided by the IIS Web Site hosting the WCF services.

适用于