I have a machine with multiple public Ip Addresses. I want to send HTTP Requests, and manually control the Source IP Address. For this, i the HttpWebRequest Class and overwrite the req.ServicePoint.BindIPEndPointDelegate
theRequest.ServicePoint.BindIPEndPointDelegate = (s, ep, retries) => {
return new IPEndPoint(IPAddress.Parse(SourceIp), 0);
};
This works fine for a single request, but it fails when trying to send multiple requests to the same Domain with different Source IP Addresses. The BindIPEndPointDelegate is only called once (on the first request), and both requests use the source IP of the first request.
After some research, i found this resource, stating that .Net reuses ServicePoints if the scheme and domain is the same. I am not sure if this is the cause of this, but i could not find a way to disable this behavior.
Help appreciated
The Solution was to set the MaxIdleTime of the ServicePoint property to 0.