WCF hostname is always 0.0.0.0

988 views Asked by At

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?

3

There are 3 answers

1
Konrad Kokosa On

Have you tried to specify ListenUri parameter for your endpoint?

<endpoint address="service" binding="webHttpBinding"
          listenUri="http://192.168.0.100:3880/MyService" 
          contract="RestServiceSample.IService" 
          behaviorConfiguration="web">
1
burning_LEGION On

use WebServiceHost for webhttpbinding

var serviceHost = new WebServiceHost(new ServiceImpl());
serviceHost.Open();
0
9Rune5 On

FWLIW: net.tcp works fine.

There is something strange going on with BasicHttpBinding's bindings and it looks like a bona fide bug to me.

It pays some attention to the URI specified. I observe that it adds a binding to the correct interface, but then it goes and slaps another binding for 0.0.0.0 ruining all good efforts put forth in the first step.