title: Windows Service C#: Accessing Mail. The Autodiscover service couldn't be located
body: <p>I have tried both the methods below but both return the result "The Autodiscover service couldn't be located."</p>
  
  <p><a href="http://msdn.microsoft.com/en-us/library/gg591267(v=EXCHG.140).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/gg591267(v=EXCHG.140).aspx</a></p>
  
  <pre><code>service.Credentials = new NetworkCredential(userData.EmailAddress, userData.Password);
  
    if (userData.AutodiscoverUrl == null)
    {
      service.AutodiscoverUrl(userData.EmailAddress, RedirectionUrlValidationCallback);
      userData.AutodiscoverUrl = service.Url;
    }
    else
    {
      service.Url = userData.AutodiscoverUrl;
    }
  
    return service;
  }
  </code></pre>
  
  <p><a href="http://code.msdn.microsoft.com/Exchange-2013-Set-pull-14c8360b#content" rel="nofollow">http://code.msdn.microsoft.com/Exchange-2013-Set-pull-14c8360b#content</a></p>
  
  <pre><code>static ExchangeService GetBinding()
          {
              // Create the binding.
              ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
  
          // Define credentials.
          service.Credentials = new WebCredentials("myemail@work.com", "password");
  
          // Use the AutodiscoverUrl method to locate the service endpoint.
          try
          {
              service.AutodiscoverUrl("myemail@work.com", RedirectionUrlValidationCallback);
          }
          catch (AutodiscoverRemoteException ex)
          {
              Console.WriteLine("Exception thrown: " + ex.Error.Message);
          }
  
          // Display the service URL.
          Console.WriteLine("AutodiscoverURL: " + service.Url);
          return service;
      }
  </code></pre>
  
  <p>In the one instance I enter my email and password, in the other its hard-coded. Both hang when attempting Autodiscoverurl and eventually fail with the message "The Autodiscover service couldn't be located." I added the references as per the tutorials and Autodiscover appears under Microsoft.Exchange.WebServices.dll ... Is there something else I'm missing?</p>