Webrequest not working in a Windows Service
<p>I am not able to use Webrequest in a windows service. It fails with error ""Unable to connect to the remote server".</p>

<pre><code>  WebRequest request = WebRequest.Create(url);
  NetworkCredential nc = new NetworkCredential("myuname","mypassword","mydomain");
  request.Proxy.Credentials = nc;

  try
  {

    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    Stream dataStream = response.GetResponseStream();
    StreamReader reader = new StreamReader(dataStream);
    string responseFromServer = reader.ReadToEnd();
  }
  catch (WebException ex)
  {
    //ex.Message is "Unable to connect to the remote server"
  }
</code></pre>

<p>The code works perfectly fine if it is a console application. </p>

<p>Could someone please tell if there is a fix?</p>
