Mark
Mark

Reputation:

Cause of exception "System.Net.WebException: The remote name could not be resolved"?

I've got a .NET client application calling my .NET web service which in turn calls a third-party web service, for example, at 'www.foo.com'.

.NET Client -> 'My Web Service' -> 'Third Party Web Service'

From Visual Studio 2008, this all works fine, that is, I'm running 'My Web Service' in localhost:someport which successfully calls the 'Third-Party Web Service'.

I then published 'My Web Service' onto a Windows 2003 Server box. Now when 'My Web Service' calls the 'Third-Party Web Service' I get the exception,
"System.Net.WebException: The remote name could not be resolved: 'www.foo.com'."

I've tried the following:

  1. On the server where I deployed 'My Web Service', I opened Internet Explorer and entered the web service address 'http://www.foo.com/somewebservice.asmx'. This was successful as the list of available web service methods were displayed.

  2. In the web.config file of 'My Web Service', I changed the 'Third-Party Web Service' URL from the web site's name to its IP address. This failed with the exception, "System.Net.Sockets.SocketException: A socket operation was attempted to an unreachable network".

  3. I then wrote a simple Windows Forms test harness to just call the 'Third-Party Web Service'. I ran this test harness on the server and it called the 'Third-Party Web Service' successfully.

  4. I then tried a different third-party web service which gave the same behaviour as in 1, 2 and 3 above.

  5. Finally I added the IP address to the "hosts" file on the server but got the same "The remote name could not be resolved" error, albeit far quicker this time! If it was a DNS issue then I wouldn't expect my tests 1 and 3 to work.

How do I fix this problem?

Upvotes: 7

Views: 30885

Answers (5)

I had this issue here in 2018 on my fancy website which i just moved to a new GoDaddy VPS: System.Net.WebException: The remote name could not be resolved: 'yada.yada'

This was happening while trying to send a SMTP, and trying to contact an external website/api. HttpRequests were failing. I checked everything. Got into IIS settings. Nothing.. All looked good (I was comparing values to my old dedicated server). I did add a Proxy 0 setting under IIS - but I don;t think that was it.

Finally I noticed I couldn't use IE on the server to browse anything on the internet either. I checked all IE settings. All looked good. I recycled by websites app pool. Nothing. FINALLY, I restarted the server. When I logged back in Noticed I COULD now browse to websites using IE. SO I tried my website and FINALLY it started working. I don;t know for sure what I did, if anything. Or if the server was just so new some setting was off at initial setup and it needed a cold restart to fix. Anyway I was happy to finally get it.. I think I looked at everything 3 times.

CHEERS

Upvotes: 0

GeoMac
GeoMac

Reputation: 93

We had the some problem with two apps running on a problem server. The error would only occur when it would run under SQL Job Agent under a schedule so it was very difficult to isolate the issue. It turned out the network folks were having trouble migrating from ISA firewall to Forefront firewall. Iamtonyzhou's solution to use "usesystemdefault" in the app.config worked nicely as a workaround until the network firewall issues are resolved. I don't think I'd ever instanciate a WebProxy object because our firewall configurations are always subject to change.

Upvotes: 0

iamtonyzhou
iamtonyzhou

Reputation: 51

 <system.net>
        <defaultProxy>
            <proxy
               usesystemdefault = "false"
         />
        </defaultProxy>
    </system.net>

cancel your proxy setting

Upvotes: 5

Kenny Evitt
Kenny Evitt

Reputation: 9801

I think this could also indicate a DNS problem, as I'm tentatively concluding about my own recent experience with this exception. In my (recent) experience, the exception stopped being thrown (and logged by my app) 'on its own'.

Upvotes: 0

Kenny Evitt
Kenny Evitt

Reputation: 9801

From Mark's comment to his own question:

It was a proxy server issue in the end. The exception message was a red herring. To fix it I created an instance of WebProxy using the IP address and port of our proxy server:

WebProxy proxy = new WebProxy( proxyServerIPAddress, Convert.ToInt32( proxyServerPort ) );       
myService.Proxy = proxy;

Upvotes: 7

Related Questions