I have a computer with a few different internet connections. LAN, WLAN, WiFi or 3G. All of these are active and the machine can use any of them.
Now I want to tell my application to use one of the available connections. For example I want to tell my application to use only WiFi while other software might use something else.
In my c# application I use classes like HttpWebRequest and HttpWebResponse.
Is this even possible?
This is somewhat advanced functionality which is abstracted away by both HttpWebRequest, WebRequest, WebClient and the like. You can, however, do this using
TcpClient(using the constructor taking a local endpoint) or using sockets and calling Socket.Bind.Bind to a local endpoint for the interface you want to use. If your local machine have ip address 192.168.0.10 for the WiFi address, then using that a local endpoint will force sockets to use that interface. Default is unbound (really 0.0.0.0) which tells the network stack to resolve the interface automatically, which you want to circumvent.
Here’s some example code based on Andrew’s comment. Note that specifying 0 as local endpoint port means that it is dynamic.