【发布时间】:2014-02-19 23:24:16
【问题描述】:
我的 WCF REST 配置有一个奇怪的问题。我想指出一个 TCP 正在侦听传入消息的网络接口(我有两个网络适配器)。但是无论我在基地址中作为主机名放置什么,TCP 总是在监听 0.0.0.0(所有接口)。
这是我的 App.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="RestServiceSample.ServiceImpl" behaviorConfiguration="ServiceBehaviour">
<endpoint address="service" binding="webHttpBinding"
contract="RestServiceSample.IService"
behaviorConfiguration="web">
</endpoint>
<host>
<baseAddresses>
<add baseAddress="http://192.168.0.100:3880/MyService"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<serviceMetadata httpGetEnabled="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
和代码:
var serviceHost = new ServiceHost(new ServiceImpl());
serviceHost.Open();
所以我想在 192.168.0.100 上监听,但是当我运行 netstat 时,我可以看到有 TCP 连接在监听 0.0.0.0:3880。
当我在绑定配置中设置hostNameComparisonMode="Exact" 时,TCP 在正确的接口上侦听,但我无法通过域名连接到服务 - 只能通过网络适配器的 IP 地址。
任何想法如何在不设置 hostNameComparisonMode="Exact" 属性的情况下使用它?
【问题讨论】:
标签: wcf rest hostname servicehost network-interface