none
Office 365 Mailbox programatic access fails: The Autodiscover service couldn't be located.

    Question

  • Not sure if this is the correct place but here goes:

    I have been given a mailbox and I have written a windows service to look into the mailbox and process email messages.

    The mailbox is of the form: createlead@api.mydomain.com

    I log in to office365 with this email address and the password and I can see the mailbox just fine.

    I try to connect with code:

    ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);

    Service.Credentials = new WebCredentials(username, password); //username as quoted above.

    I get the following error:

    Microsoft.Exchange.WebServices.Data.AutodiscoverLocalException: The Autodiscover service couldn't be located.
       at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetLegacyUserSettings[TSettings](String emailAddress, List`1 redirectionEmailAddresses, Int32& currentHop)
       at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetLegacyUserSettings[TSettings](String emailAddress)
       at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetLegacyUserSettings(String emailAddress, List`1 requestedSettings)
       at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetUserSettings(String userSmtpAddress, UserSettingName[] userSettingNames)
       at Microsoft.Exchange.WebServices.Data.ExchangeService.GetAutodiscoverUrl(String emailAddress, ExchangeVersion requestedServerVersion, AutodiscoverRedirectionUrlValidationCallback validateRedirectionUrlCallback)
       at Microsoft.Exchange.WebServices.Data.ExchangeService.AutodiscoverUrl(String emailAddress, AutodiscoverRedirectionUrlValidationCallback validateRedirectionUrlCallback)
       at LeadProcessor.Library.MailboxHelper.GetBinding(String Username, String Password) in C:\...\LeadProcessor\LeadProcessor.Library\MailboxHelper.cs:line 472
       at LeadProcessor.Library.MailboxHelper.GetEmailHelper(String Username, String Password) in C:\...\LeadProcessor\LeadProcessor.Library\MailboxHelper.cs:line 491
       at LeadProcessor.WindowsService.Service1.ProcessMailbox(Organisation Config)

    I have tried the Remote Connectivity Analyser but can't work out which option I should be choosing (Office 365 General Tests? Single Sign On?)

    Tried this and got error: The domain  isn't a federated domain.

    Not sure if this is saying I am using the wrong option in the Remote Connectivity Analyser or if there is something wrong with the mailbox.

    Can anyone help?

    Tuesday, November 26, 2013 1:18 PM

All replies

  • I ran the "<label for="testSelectWizard_ctl09_cloudSelectionList_radioO365ExchangeDns">Office 365 Exchange Domain Name Server (DNS) Connectivity Test</label>" for "mydomain.com" and it passed.

    I am wondering now what I have to do to get the "api.mydomain.com" to work in Office365. 

    I can certainly log in to the mailbox.

    Tuesday, November 26, 2013 4:58 PM
  • Hi,

    Thank you for posting in the MSDN Forum.

    Since the issue is more relate to the development of Exchange Server, I'd like to move it to Exchange Server Development forum.

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us.

    Thanks for your understanding.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, November 27, 2013 6:09 AM
  • In the 2013 (Wave15) version of Office365 there is now a single endpoint for EWS so in theory you don't need to use Autodiscover and you can just use

    https://outlook.office365.com/EWS/Exchange.asmx if you use Autodiscover this is the URL that will be returned.

    If you want to track down why you Autodiscover is failing you can enable tracing http://msdn.microsoft.com/en-us/library/dd633676(v=exchg.80).aspx and have a look at the verbose output from the Autodiscover. (things like having a local Exchange Org or issues with the way DNS is configured at the client end are usually the cause).

    I'd also suggest you try using the EWSEditor as another client to do some localized testing http://ewseditor.codeplex.com/

    Cheers
    Glen

    Thursday, November 28, 2013 6:51 AM
  • Hi,

    We are having the same issue at our company.  IT migrated all users to Office 365 and our in-house applications which referenced our on-premise exchange no longer works.

    Was this issue resolved?

    1.  I've tried changing the service Url to https://outlook.office365.com/ews/exchange.asmx and passed the mailbox credentials but I get 401 Unauthorized error.

    2.  Tried with Autodiscover but get The Autodiscover service couldn't be located error.  

    Enabled trace and end of the trace indicates following: 

    <Trace Tag="AutodiscoverConfiguration" Tid="10" Time="2018-12-07 14:13:05Z">
     failed: WebException (The remote server returned an error: (401) Unauthorized.)

    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="10" Time="2018-12-07 14:13:05Z">
    Trying to get Autodiscover host from DNS SRV record for mycompanyname.mail.on
    microsoft.com.
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="10" Time="2018-12-07 14:13:05Z">
    DnsQuery returned error error 'DNS name does not exist' error code 0x0000232B.
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="10" Time="2018-12-07 14:13:05Z">
    No appropriate SRV record was found.
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="10" Time="2018-12-07 14:13:05Z">
    No matching Autodiscover DNS SRV records were found.
    </Trace>

    My other challenge is that our IT admin's knowledge of web services is almost non existing, and I have no Exchange knowledge too, so I have no idea what else needs to be enabled or what other permissions are required to get the code to work with Office365.

    Any help is greatly appreciated.

    Thank you.


    ml99

    Friday, December 7, 2018 3:52 PM
  • Try the Remote connectivity analyzer https://testconnectivity.microsoft.com/ that should give you a detailed output of what is happening. Also make sure you use the UPN for the account as the down-level format won't work.  

    Also if you located in Germany,China or a US Government tenant then https://outlook.office365.com/ews/exchange.asmx  won't be the correct URL

    Cheers
    Glen

    Sunday, December 9, 2018 11:05 PM
  • Thanks Glen for your response.  I ran a test and get the following error:

    An HTTP 401 Unauthorized response was received from the remote Unknown server. This is usually the result of an incorrect username or password. If you are attempting to log onto an Office 365 service, ensure you are using your full User Principal Name (UPN).

    I've logged in as the user with the credentials I'm using.  I'm able to access the mailbox through the web mail interface, so I'm confused as to what credentials it's referring to when it indicates>>incorrect username or password.

    Our company is located in Toronto, Canada, so https://outlook.office365.com/ews/exchange.asmx should work?

    Is there any other setting/permissions/authentication that needs to be done?

    Thanks for any help.


    ml99

    Monday, December 10, 2018 1:59 PM
  • https://outlook.office365.com/ews/exchange.asmx should work okay. Something doesn't sound correct to me if you can logon to OWA then the Remote connectivity analyzer should be able to connect okay.  I would say try the EWSeditor and try to connect to the Office365 endpoint and if that fails try to connect to your onprem ews endpoint maybe the user hasn't actually been moved.

    Cheers
    Glen

     
    Monday, December 10, 2018 11:36 PM