HttpWebRequest and BindIPEndPointDelegate getting socket exception
- by Evgeny Gavrin
I've got c# code running on a computer with multiple network interfaces, and the following code to select an IP address for a HttpWebRequest to bind ServicePoint:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(remoteFilename);
request.KeepAlive = false;
request.ServicePoint.BindIPEndPointDelegate = delegate(
ServicePoint servicePoint,
IPEndPoint remoteEndPoint,
int retryCount) {
return new IPEndPoint(IPAddress.Parse(ipAddr), 0);
};
But it works only for one of the available network interfaces. Trying to access remote server through others throws an exception: System.Net.WebException: Unable to connect to the remote server --- System.Net.Sockets.SocketException: A socket operation was attempted to an unreachable network
How can it be solved?