Connecting with Office 365-Autodiscover could not be located RRS feed

  • Question

  • Hi ,

    I have built a VB project where I was using API 1.2 to connect to exchange server 2010 using webservices.

    To be more specific , I was connecting in my Office 365 which had exchange 2010.

    I was using the below code where the Me.ExchangeVersion1 is an enumaration.

    1 for exchange 2007 ,etc... Exchange 2013 has number 4.

    But I'm getting now in exchange 2013(office 365) and error which says.

    The Autodiscover service couldn't be located.

     I'm changing the exchangeversion to 4 and leave the rest of the code intact.       

    Am I doing anything wrong ?

    I have asked a long time ago about if there will be changes between API 1.2 and API 2.0 and ,don't remember the name ,someone from Microsoft told me that no changes will be made unless you want to use new features of Exchange 2013 which I didn't want that. In other words , business as usual. Can anyone assist me on this ? Is it something that I need to look for ?Or change in my code ?

     Public Function GetBinding() As ExchangeService
            ' Create the binding.
            Dim service As New ExchangeService(Me.ExchangeVersion1)

            ' Define credentials.
            service.Credentials = New WebCredentials(UserName, PassWord)

            ' Use the AutodiscoverUrl method to locate the service endpoint.

                service.AutodiscoverUrl(UserName, _
                        New AutodiscoverRedirectionUrlValidationCallback( _
                            AddressOf MycustomClass.RedirectionUrlValidationCallback))

            Catch ex As AutodiscoverRemoteException
                Me.ErrorCode = -1
                Throw ex
            End Try

            Return service
        End Function

      ' Create the callback to validate the redirection URL.
        Private Shared Function RedirectionUrlValidationCallback(ByVal redirectionUrl As String) As Boolean
            ' Perform validation.
            Return (redirectionUrl = _
        End Function

    • Edited by zakkar Thursday, June 13, 2013 11:53 AM
    Thursday, June 13, 2013 9:19 AM


All replies

  • Any ideas for what to look for ?
    Thursday, June 20, 2013 4:57 AM
  • The first thing would be to test AutoDiscover with the same credentials your using in https://www.testexchangeconnectivity.com/ (use the Office365 Tab)

    The next thing would be to enable Tracing and look at the Autodiscover Traces to see where its failing http://msdn.microsoft.com/en-us/library/exchange/dd633676(v=exchg.80).aspx


    Thursday, June 20, 2013 7:23 AM
  • Hi Glen ,

    I have already tried those.

    Here is a strange thing that is happening. 

    I'm performing a loop through all the exchange users I have.

    I'm connecting to the first two users , everything works OK. I am able to read their inbox-es  , their emails etc...

    When the loop is going to the third account I get the error for all the rest.

    If I try after a while for the third account that I have the problem it is working!!!!. That means that the credentials , my code and everything else is correct.

    I have a suspicion that the "Cloud" sees that after the second user someone is trying to hack it ???? and it locks ???? Is this possible ?

    If I do this one user each time the code is working fine. The problem is that after the second user if I do this in one loop the cloud kind of Locks ??? Not sure though.

    Is there any property that I can change , or a power shell command to avoid this ?

    Until last last Wednesday I was able to work and loop through the users without problem. But something changed (don't know what ) in the cloud and I'm facing this issue.

    I checked the autodiscovered service and I got this

    Request error: The remote server returned an error: (401) Unauthorized. 

    Request error: The remote name could not be resolved: 'mycompany.onmicrosoft.com'

    No Autodiscover endpoints are available for host myserver.onmicrosoft.com

    But this is not accurate because If I login to the first user and wait , works , If I login to the second user and wait it works etc etc....

    I run out of ideas.

    Appreciate any help on this.

    thank you

    Wednesday, July 3, 2013 7:55 AM
  • What do the traces look like when its failing ?

    It could be throttling by default you can't have any more then 10 simulatenous connections with one account. What you could try to do as a test is use Impersonation http://msdn.microsoft.com/en-us/library/exchange/gg194012%28v=exchg.140%29.aspx, this will mean the throttling budget of the mailbox your accessing will be charged rather then the service account your using. Are you using the same accout in other applications ?

    You should be able to tell with the Traces why its failing, with 2013 you can bypass Autodiscover and just use the loadbalencer address https://outlook.office365.com/ews/exchange.asmx to test if this makes a differance http://blogs.msdn.com/b/mstehle/archive/2013/04/17/changes-in-managing-affinity-for-ews-subscriptions.aspx.


    • Marked as answer by zakkar Saturday, September 14, 2013 5:48 AM
    Wednesday, July 3, 2013 10:59 AM
  • Hi Glen ,

    I'm not using the same account in other applications. I have 20 exchange users and I'm connecting to the cloud in a loop. 

    I'm only having one connection each time. I'm connecting one time ,  reading the inbox for one user (all the messages) , the sent items folder and then I set the MyExchangeService variable to null. Setting the service = nothing means that I'm disconnecting. Correct ?Then I'm taking the other user ,  connecting to the cloud , reading inbox, sent items etc etc.

    Is there any other command for disconnecting ? I searched for "dispose" or "close" or "clear" but I didn't find any similar.That is why I used the MyService=nothing.

    I cannot use 2013 because the company has 2010. Telling them to upgrade to 2013 has to do with the cloud service. They will have to contact with the provider , don't know how this will it cost etc etc etc....A lot of trouble if you understand my point.

    I will try and use the impersonating user and see what happens.

    I'll check and revert

    thank you

    Thursday, July 4, 2013 7:33 AM
  • What trace files do you want me to send you ?
    Thursday, July 4, 2013 7:39 AM
  • Hi Glen ,

    You were right. Putting the https://outlook.office365.com/ews/exchange.asmx   in the Service.URL did the trick.

    I think that something is going on with the IP addresses they gave me ? Something is not being setup correctly ?. Perhaps didn't link the external IP address with the Autodiscover Service ?

    I will talk with the provider and see what is going on.

    Thank you Glen

    Saturday, September 14, 2013 5:48 AM
  • Hello , I have the same scenario with "The Autodiscover service couldn't be located."

    But the problem is that this error appears on the customer's side, but not my side. even when I try to use their credentials I manage to connect to their calendar , but they cannot . can you tell me why does this happen ? 


    Thursday, January 16, 2014 4:46 PM
  • It depends on your code if you are using the Managed API in its default mode it will perform a lookup of Active Directory first to find any Exchange installations for that domain first and then it will try DNS. Its generally a good idea to use

    Service.EnableScpLookup = false;

    To exclude the SCP lookup and just rely on DNS as that will eliminate any issue with the SCP record in a Local Active Directory. If they are using Hybrid mode  eg some OnPrem and some cloud mailboxes you may also be having issue. I would suggest you do some testing at the customer site with the EWSeditor http://ewseditor.codeplex.com/ (In Tools use the Autodiscover viewer). That will tell you where the Autodiscover requests are going and what's going wrong.


    Friday, January 17, 2014 2:56 AM
  • HEllo , I have done several tests with ewseditor , and it worked at my machine but it did not work on the customer's I turned off the SCP Lookup and gave me the same error as following 

    Exception details:
    Message: The Autodiscover service couldn't be located.
    Type: Microsoft.Exchange.WebServices.Data.AutodiscoverLocalException
    Source: Microsoft.Exchange.WebServices
    Stack Trace:
       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 EWSEditor.Exchange.EwsProxyFactory.DoAutodiscover(EmailAddress emailAddress) in E:\msft tools\ewseditor\EWSEditor\Exchange\EwsProxyFactory.cs:line 35
       at EWSEditor.Exchange.EwsProxyFactory.DoAutodiscover() in E:\msft tools\ewseditor\EWSEditor\Exchange\EwsProxyFactory.cs:line 28
       at EWSEditor.Forms.ServiceDialog.BtnOK_Click(Object sender, EventArgs e) in E:\msft tools\ewseditor\EWSEditor\Forms\Dialogs\ServiceDialog.cs:line 114
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

    I am not really sure how to read the exception messages, but is there any specific logs you would like me to show you? and can you tell me how to read them , or which part are you looking at ? 

    I would like to add , that they are using kind of hybrid mode, and that is according to our partner who is working with them. 



    Friday, January 17, 2014 10:00 AM
  • Hi Glen I fall in the same issue. My one user getting the "The Autodiscover service couldn't be located." So I use the address like you mention above (" https://outlook.office365.com/ews/exchange.asmx ") which work for me!!

    I need help why AutoDiscover not working. Is there any issue with my user?


    Thursday, February 20, 2014 12:10 PM
  • Have you tried using https://testconnectivity.microsoft.com/ with that user to do some testing ?

    You might want to check if MAPI is enabled for that account your trying to use, you can do this using Get-Casmailbox in Remote PowerShell. What I've found is if you disable MAPI on o365 that affects the way autodiscover works for that user. Also is that user has a Kiosk licence assigned to it then Autodiscover won't work either (while EWS should).


    Friday, February 21, 2014 1:59 AM
  • Hi Glen, 

    Thank you for reply.

    Here I get the error detail by testconectivity.

    The Microsoft Connectivity Analyzer is attempting to retrieve an XML Autodiscover response from URL https://webmail.My.com/autodiscover/Autodiscover.xml for user MyUserEmail.
    The Microsoft Connectivity Analyzer failed to obtain an Autodiscover XML response.

    Additional Details

    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).
    Headers received:
    request-id: 4b4e219e-b19f-4617-b1ac-69ad7ec1eee0
    Server: Microsoft-IIS/8.0
    WWW-Authenticate: Negotiate,NTLM,Basic realm="webmail.MyDomain.com"
    X-Powered-By: ASP.NET
    X-FEServer: EX2013FE03
    Date: Mon, 24 Feb 2014 05:55:46 GMT
    Content-Length: 0
    Elapsed Time: 578 ms.

    But I can login through web and also I can get connect to service with this user if I give service URL directly like you told "https://outlook.office365.com/ews/exchange.asmx".

    Is there any difference in it? AutoDicovery Or Giving URL Directly.

    Monday, February 24, 2014 6:12 AM
  • >> Is there any difference in it? AutoDiscovery Or Giving URL Directly.

    Currently no all you will get back from AutoDiscover in Office365/EXO is https://outlook.office365.com/ews/exchange.asmx . Which is the Load balanced Endpoint. However this may or may not change in the future.

    From the response your getting it doesn't look like the Office365 endpoint is being queried.

    X-FEServer: EX2013FE03

    (that servername doesn't look like an Office365 servername more somebodies onprem environment)

    Are you running in Hybrid mode ?


    Tuesday, February 25, 2014 4:29 AM
  • Thanks Glen,

    Actually I have application which is use to transfer email to office 365 of any account in Office 365. So Thats why I was using  the Autodiscover but it start get fail on few of the accounts. 

    I have an orgnization accounts which have office 365 logins. 

    Those accounts are working fine with https://outlook.office365.com/ews/exchange.asmx instead of AutoDiscover.

    Thursday, February 27, 2014 6:27 AM