Bind WCF webservice to specific network interface / IP

Posted by Markus on Stack Overflow See other posts from Stack Overflow or by Markus
Published on 2010-05-12T16:07:47Z Indexed on 2010/05/29 4:42 UTC
Read the original article Hit count: 310

Filed under:
|
|
|
|

On a machine with multiple network cards I need to bind a WCF webservice to a specific network interface. It seems that the default is to bind on all network interfaces.

The machine has two network adapters with the IPs 192.168.0.10 and 192.168.0.11. I have an Apache running that binds on 192.168.0.10:80 and need to run the webservice on 192.168.0.11:80. (Due to external circumstances I cannot choose another port.)

I tried the following:

string endpoint = "http://192.168.0.11:80/SOAP";
ServiceHost = new ServiceHost(typeof(TService), new Uri(endpoint));
ServiceHost.AddServiceEndpoint(typeof(TContract), Binding, "");
// or: ServiceHost.AddServiceEndpoint(typeof(TContract), Binding, endpoint);

But it doesn't work; netstat -ano -p tcp always shows the webservice listening on 0.0.0.0:80, which is all interfaces (if I got that correct). When I start Apache first, it correctly binds to the other interface, which in turn prevents the WCF service to bind to "all".

Any ideas?

© Stack Overflow or respective owner

Related posts about wcf

Related posts about binding