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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With