question

ExchangeOnline444-2641 avatar image
0 Votes"
ExchangeOnline444-2641 asked ·

EWS Java API 2.0 - The Autodiscover service couldn't be located

Hi,

I am using EWS Java API 2.0 to access user mailboxes from Exchange 2019 and O365 using autodiscoverUrl() method as EWS URL might change with new Client Access servers.

PFB the code snippet:

  private static ExchangeService exchangeService;
    
     private static void usingAutodiscovery() {
         exchangeService = new ExchangeService();
         try {
             exchangeService.setTraceEnabled(true);
             exchangeService.setCredentials(new WebCredentials("username", "password", "domain.com"));
             // Set the URL.
             exchangeService.autodiscoverUrl(username@domain.com, new RedirectionUrlCallback());
                
             Folder inbox = Folder.bind(exchangeService, WellKnownFolderName.Inbox);
             System.out.println("messages: " + inbox.getTotalCount());
                
         } catch (Exception e) {
             e.printStackTrace();
         }
     }
        
     public static void main(String[] args) {
         usingAutodiscovery();
     }
    
     public static class RedirectionUrlCallback implements IAutodiscoverRedirectionUrl {
         public boolean autodiscoverRedirectionUrlValidationCallback(String redirectionUrl) {
             return redirectionUrl.toLowerCase().startsWith("https://");
       }
     }
 }


But I am getting the below error:

 microsoft.exchange.webservices.data.autodiscover.exception.AutodiscoverLocalException: The Autodiscover service couldn't be located.
     at microsoft.exchange.webservices.data.autodiscover.AutodiscoverService.internalGetLegacyUserSettings(AutodiscoverService.java:742)
     at microsoft.exchange.webservices.data.autodiscover.AutodiscoverService.getLegacyUserSettings(AutodiscoverService.java:521)
     at microsoft.exchange.webservices.data.autodiscover.AutodiscoverService.internalGetLegacyUserSettings(AutodiscoverService.java:959)
     at microsoft.exchange.webservices.data.autodiscover.AutodiscoverService.getUserSettings(AutodiscoverService.java:1846)
     at microsoft.exchange.webservices.data.core.ExchangeService.getAutodiscoverUrl(ExchangeService.java:3615)
     at microsoft.exchange.webservices.data.core.ExchangeService.autodiscoverUrl(ExchangeService.java:3572)
     at com.sample.autodiscover.UsingAutodiscover2.usingAutodiscovery(UsingAutodiscover2.java:47)
     at com.sample.autodiscover.UsingAutodiscover2.main(UsingAutodiscover2.java:60)


We have below details configured:
AutodiscoverInternalUri = https://autodiscover.domainname.com/Autodiscover/Autodiscover.xml
External EWS URL = https://domainname.com/ews/exchange.asmx






office-exchange-hybrid-itprooffice-exchange-server-dev
10 |1000 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

ZhengqiLou-MSFT avatar image
0 Votes"
ZhengqiLou-MSFT answered ·

Hi @ExchangeOnline444-2641 ,

Try to replace

 exchangeService.setCredentials(new WebCredentials("username", "password", "domain.com"));

with

 exchangeService.setCredentials(new WebCredentials("emailAddress", "password"));

Also test the autodiscover service with ECRCA
Regards,
Lou


If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

· 4 · Share
10 |1000 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.

Hi @ZhengqiLou-MSFT ,

As suggested, I tested by only passing email credentials, but the issue still persists.

Additionally, I also tried testing autodiscover service using RCA tool for Outlook Connectivity and I noticed that tests for MAPI over HTTP connectivity was verified successfully. However, tests for RPC over HTTP connectivity failed.

Could you please confirm if this is the right approach and if this is expected?

Thanks!

0 Votes 0 ·

Hi @ExUser44-0578 ,

Seems like it's normal, I did the same test and got a same result.
I think that's because MAPI is used by default after Exchange 2016 but not RPC over HTTP, in another word, it's not running.

As for the API, i found an article about Basic Authentication for EWS will be decommissioned on October 13th, 2020
As a result, we can't use original auth method like Address + Password.

Best regards,
Lou


If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

0 Votes 0 ·

Hi @ZhengqiLou-MSFT , thanks for your input.

We tried using modern authentication(OAuth using Client Credentials), but we are still getting the same exception, AutodiscoverLocalException.

We are basically trying to access On-premise and Online mailboxes in our Hybrid environment. Is there any other way this can be achieved?

Thanks!

0 Votes 0 ·
Show more comments