none
Autodiscover not working from c# code after outlook migrated to o365 server from on premise server RRS feed

  • Question

  • Hi ,

    After migration of my outlook to o365 server, Autodiscover functionality does not work from c# code . Probably an authentication issue. 

    Could you please let me know how can it be fixed.

    Thanks in advance!


    Friday, February 10, 2017 11:10 AM

Answers

  • Well. I am able to resolve it now. In fiddler, you have to set "Automatically Authenticate" to true. Also keep fiddler open while debugging. 

    Thanks for the time guys! 

    Hope this experience helps someone

    • Marked as answer by Wanderlust007 Tuesday, February 14, 2017 11:37 AM
    Tuesday, February 14, 2017 11:37 AM
  • Well. I am able to resolve it now. In fiddler, you have to set "Automatically Authenticate" to true. Also keep fiddler open while debugging. 

    Thanks for the time guys! 

    Hope this experience helps someone

    • Marked as answer by Wanderlust007 Tuesday, February 14, 2017 11:38 AM
    Tuesday, February 14, 2017 11:38 AM

All replies

  • Hello,

    > Autodiscover functionality does not work from c# code .

    What code exactly do you have now? What error do you get in the code? Could you please be more specific?


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Friday, February 10, 2017 12:25 PM
  • What exactly does not work? Namespace.Autodiscover?

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Friday, February 10, 2017 4:10 PM
  • Hi Eugene,

    Thanks for the reply.

    In my application, I use the below code

      public static ExchangeService ExchangeService()
            {
                try
                {
                    if (HttpContext.Current.Session["exchangeService"] == null)
                    {
                        Log.Trace($"Getting Exchange service for first time with userid:'{UserId}'");
                        var pass = Decrypt(HttpContext.Current.Session["pass"].ToString());
                   
                        ExchangeService service1 = new ExchangeService(ExchangeVersion.Exchange2013_SP1)
                        {
                            TraceEnabled = true,
                            Credentials = new WebCredentials("dj_dev@myorg.com", pass)
                        };

                   service1.AutodiscoverUrl("dj_dev@myorg.com", RedirectionUrlValidationCallback);

                        service.GetInboxRules();
                        HttpContext.Current.Session["exchangeService"] = service;
                    }
                }

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

                Uri 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;
            }

    As my outlook account has been migrated to o365 server(not on premise), the code below returns "The Autodiscover service could not be located"

      service1.AutodiscoverUrl("dj_dev@myorg.com", RedirectionUrlValidationCallback);

    But the same code when accessed with credentials(email and password) of a developer who has his outlook hosted in on premise server, the Autodicsover works and fetches the url. For my case, it should fetch url "https://outlook.office365.com/owa/EWS/Exchange.asmx"

    On further investigation with fiddler it seems that it is an authorization issue with o365 server. 

    Please come back to me for in case further details are required from my side. 

    Appreciate your help !






    • Edited by Wanderlust007 Monday, February 13, 2017 11:14 AM update with more details
    Monday, February 13, 2017 11:08 AM
  • Does auto discover work from Outlook if you Ctrl + right click on the Outlook tray icon and select "Test Emai lAutodiscover"?

    Why do you upper case the user name?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Monday, February 13, 2017 7:34 PM
  • Well. I am able to resolve it now. In fiddler, you have to set "Automatically Authenticate" to true. Also keep fiddler open while debugging. 

    Thanks for the time guys! 

    Hope this experience helps someone

    • Marked as answer by Wanderlust007 Tuesday, February 14, 2017 11:37 AM
    Tuesday, February 14, 2017 11:37 AM
  • Well. I am able to resolve it now. In fiddler, you have to set "Automatically Authenticate" to true. Also keep fiddler open while debugging. 

    Thanks for the time guys! 

    Hope this experience helps someone

    • Marked as answer by Wanderlust007 Tuesday, February 14, 2017 11:38 AM
    Tuesday, February 14, 2017 11:38 AM