-1
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1)
{
    Credentials = new WebCredentials("usrname", "pass#1234")
};

//to add logic for itemview
service.AutodiscoverUrl("emailaddress@test.com");

When I'm running the above code in my application hosted on iis , it is throwing an error 'autodiscover service couldn't be located'.

But when I am running the same on visual studio development server it is working fine.
How to solve this issue?

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
rohit singh
  • 550
  • 1
  • 11
  • 32

2 Answers2

0

Try to add this code in your auto-discovery; it works perfectly in my application hosted in IIS.

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1)
{
    Credentials = new WebCredentials("usrname", "pass#1234")
};

//to add logic for itemview
service.AutodiscoverUrl("emailaddress@test.com", RedirectionUrlValidationCallback);

private static bool RedirectionUrlValidationCallback(string redirectionUrl)
    {
        // The default for the validation callback is to reject the URL.
        var result = false;

        var redirectionUri = new Uri(redirectionUrl);

        // Validate the contents of the redirection URL. In this simple validation
        // callback, the redirection URL is considered valid if it is using HTTPS
        // to encrypt the authentication credentials. 
        if (redirectionUri.Scheme == "https")
        {
            result = true;
        }
        return result;
    }
jtabuloc
  • 2,479
  • 2
  • 17
  • 33
  • have you take a loook at this http://stackoverflow.com/questions/19909442/exchange-impersonation-in-service-account-autodiscover-service-couldnt-be-local – jtabuloc Aug 05 '15 at 13:36
  • when i run the code using VS dev server it runs fine but when hosting on IIS at my system it is not working. The above link doesn't solve it. – rohit singh Aug 06 '15 at 05:14
0

There are a lot of reasons that you could get that error. You need to enable tracing with all of the Autodiscover-related trace tags turned on, then review what's happening to find the cause. It could be DNS, credentials, firewalls, etc, etc.

Jason Johnston
  • 17,194
  • 2
  • 20
  • 34