HttpWebRequest and BindIPEndPointDelegate getting socket exception

Posted by Evgeny Gavrin on Stack Overflow See other posts from Stack Overflow or by Evgeny Gavrin
Published on 2012-07-10T03:10:12Z Indexed on 2012/07/10 3:15 UTC
Read the original article Hit count: 963

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about c#

Related posts about networking