Search code examples
c#web-servicesexchange-serverexchangewebservicesexchange-server-2007

Microsoft.Exchange.WebServices.Data.AutodiscoverLocalException Trying to Read Email From EWS C#


I'm Developing a Console Application for testing purpose in C#. This Application is made to read the Email from MS Exchange Web Service server2007. But I can't get it working for a while. should I include some code in the App.config? which one! here is this exception

AutodiscoverLovalException

Even I make use of configurattion.appSettings() to pass the key and the value, Still getting the same handler. this really frustrate a lot.

Here is my tested code:

 static void Main(string[] args)
    {
        // Create the binding.
        ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
        service.Credentials = new WebCredentials("user", "pass", "domain");

        // Set the URL.
        service.AutodiscoverUrl("user@domain.com",);
    }
    static bool RedirectionCallback(string url)
    {
        return url.ToLower().StartsWith("https://");
    }

Anyone have an idea?


Solution

  • In your given code, you do not call the method RedirectionCallback.

    Edit line 8 to the following:

    service.AutodiscoverUrl("user@domain.com", RedirectionCallback);