Bind WCF webservice to specific network interface / IP
- by Markus
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?