Why do I get an Unable to connect to the remote server exception from a web app and not console app?
It could be due to differences in the proxy settings between applications. Check out the MSDN documentation around the Default Proxy element in config file.
I too was in a similar situation while using HttpClient
class from System.Net.Http
namespace. I was trying to make a network call which goes through the company proxy server.
While this HttpClient
call was able to successfully resolve the IP of the dns when called from a console app in visual studio the dns resolution failed when the call was made from a Web API. And it turned out that I had to have this entry in the web.config of the web api app.
<system.net>
<defaultProxy />
</system.net>
Credit to Mark 909's answer for pointing me in right direction. Please see Default Proxy for additional information.
c#httpclientwebapi