question

78669366 avatar image
0 Votes"
78669366 asked GlenScales-6756 answered

The Autodiscover service couldn't be located

Hi

Exchange 365.

I am using below code to get exchange service however I am getting 'The Autodiscover service couldn't be located' error on the last line.

  Dim service As New ExchangeService
    
  service.Credentials = New NetworkCredential(userEmailAddress, userPassword)
    
   service.AutodiscoverUrl(userEmailAddress, Function(a) True)

What am I doing wrong? The email and password are valid and can login to o365 site fine and access Outlook etc.

I have searched for the solution but the ones I found were for on-premises Exchange.

Thanks

Regards

office-exchange-server-dev
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

GlenScales-6756 avatar image
0 Votes"
GlenScales-6756 answered

The above code will try to use Basic authentication which is going away and may have already been disabled in your tenant https://techcommunity.microsoft.com/t5/exchange-team-blog/basic-authentication-and-exchange-online-february-2021-update/ba-p/2111904 .

Easy way to test it try setting the URL and access the inbox eg

   rem service.AutodiscoverUrl(userEmailAddress, Function(a) True)
    
 service.Url = New Uri("https://outlook.office365.com/ews/exchange.asmx")
 Dim Inbox As Folder = Folder.Bind(service, WellKnownFolderName.Inbox)

What you should be doing is implementing oAuth https://docs.microsoft.com/en-us/exchange/client-developer/exchange-web-services/how-to-authenticate-an-ews-application-by-using-oauth instead of using Basic. You can also use the Microsoft Graph API rather then EWS which is more modern API.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.