title: Cause of exception "System.Net.WebException: The remote name could not be resolved"?
body: <p>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'.</p>
  
  <pre><code>.NET Client -&gt; 'My Web Service' -&gt; 'Third Party Web Service'
  </code></pre>
  
  <p>From Visual Studio 2008, this all works fine, that is, I'm running 'My Web Service' in <code>localhost:someport</code> which successfully calls the 'Third-Party Web Service'.</p>
  
  <p>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,<br>
  "System.Net.WebException: The remote name could not be resolved: 'www.foo.com'." </p>
  
  <p>I've tried the following:</p>
  
  <ol>
  <li><p>On the server where I deployed 'My Web Service', I opened Internet Explorer and entered the web service address '<a href="http://www.foo.com/somewebservice.asmx" rel="nofollow noreferrer">http://www.foo.com/somewebservice.asmx</a>'.
  This was successful as the list of available web service methods were displayed.</p></li>
  <li><p>In the <code>web.config</code> 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".   </p></li>
  <li><p>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.</p></li>
  <li><p>I then tried a different third-party web service which gave the same behaviour as in 1, 2 and 3 above.</p></li>
  <li><p>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.</p></li>
  </ol>
  
  <p>How do I fix this problem?</p>