1

I have strange problem with my WCF REST configuration. I would like to point a network interface on which TCP is listening for incoming messages (I have two network adapters). But whatever I put as a hostname in base address, TCP is always listening on 0.0.0.0 (all interfaces).

This is my 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>

And code:

var serviceHost = new ServiceHost(new ServiceImpl());
serviceHost.Open();

So I want to listen on 192.168.0.100 but when I run netstat I can see that there is TCP connection listening on 0.0.0.0:3880.

When I set hostNameComparisonMode="Exact" in binding configuration then TCP listening on correct interface but I cannot connect to service by domain name - only by IP address of network adapter.

Any ideas how to play with that without setting hostNameComparisonMode="Exact" property?

4

3 回答 3

0

用于WebServiceHostwebhttpbinding

var serviceHost = new WebServiceHost(new ServiceImpl());
serviceHost.Open();
于 2013-12-03T22:05:34.050 回答
0

您是否尝试ListenUri为端点指定参数?

<endpoint address="service" binding="webHttpBinding"
          listenUri="http://192.168.0.100:3880/MyService" 
          contract="RestServiceSample.IService" 
          behaviorConfiguration="web">
于 2013-12-03T22:03:43.900 回答
0

FWLIW:net.tcp 工作正常。

BasicHttpBinding 的绑定发生了一些奇怪的事情,对我来说它看起来像是一个真正的错误。

它会注意指定的 URI。我观察到它为正确的界面添加了一个绑定,但随后它又为 0.0.0.0 打了另一个绑定,破坏了第一步中所做的所有努力。

于 2014-02-19T15:24:16.017 回答