Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I get an Unable to connect to the remote server exception from a web app and not console app?

I have a asmx web service running on a test server that has anonymous access enabled.

When I add the web reference to a console application and call a simple Hello World method like so:

PivotService.PivotService p = new PivotService.PivotService();
String s = p.SayHello();

When I do exactly the same thing in the page load of a web application I get a System.Net.WebException: {"Unable to connect to the remote server"}.

The inner exception is {"No connection could be made because the target machine actively refused it 127.0.0.1:8888"}, errorCode 10061.

Why would this work from a console app and not a web app?

like image 475
woggles Avatar asked Nov 22 '11 09:11

woggles


2 Answers

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.

like image 177
Mark 909 Avatar answered Sep 22 '22 16:09

Mark 909


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

like image 42
Kiran R Avatar answered Sep 23 '22 16:09

Kiran R