I try to connect to a web service hosted on a different server using the WebRequest Class. The web service returns a string as a Response. While doing so I get an Error:
If you have config file transforms then ensure you have the correct config selected within your publish profile. (Publish > Settings > Configuration)
The issue disappeared for me when I started Fiddler. Was using it on my machine before having the issue. Probably something with Fiddler being proxy.
Had the same problem, it turned out it was the WindowsFirewall blocking connections. Try to disable WindowsFirewall for a while to see if helps and if it is the problem open ports as needed.
After six days I find the answer which make me crazy! The answer is disable proxy at web.config file:
<system.net>
<defaultProxy>
<proxy usesystemdefault="False"/>
</defaultProxy>
</system.net>
Add new WebProxy() for the proxy setting , where you are creating a web request.
Example :-
string url = "Your URL";
System.Net.WebRequest req = System.Net.WebRequest.Create(url);
req.Proxy = new WebProxy();
System.Net.WebResponse resp = req.GetResponse();
Where req.Proxy = new WebProxy() handle the proxy setting & helps the code to work fine.
I had a similar issue, trying to run a WCF-based HttpSelfHostServer in Debug under my VisualStudio 2013. I tried every possible direction (turn off firewall, disabling IIS completely to eliminate the possibility localhost port is taken by some other service, etc.).
Eventually, what "did the trick" (solved the problem) was re-running VisualStudio 2013 as Administrator.
Amazing.