none
Strange error in auto-discover using EWS... RRS feed

  • Question

  • Hi,

    The test environment:

    Parent domain: parent.domain.

    Child domain: child.parent.domain

    SMTP domain: smtp.domain

    SIP domain: sip.domain

    Test PC join the "child.parent.domain" and login with "child\test1", this account's email address is "test1@sip.domain", outlook in this PC works fine, but EWS raise a exception about getting user settings.

    EWS auto-discover code:

    AutoDiscoverExchangeWebServices

    {

    ...

    _ExchangeService = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
    _ExchangeService.TraceEnabled = true;

    _ExchangeService.Credentials = new WebCredentials(test1, password, child.parent.domain);

    _ExchangeService.AutodiscoverUrl("test1@sip.domain", AutoDiscoverValidationCallback);

    ...

    }

    Logs:

    =====================AutodiscoverConfiguration======================== 
    <Trace Tag="AutodiscoverConfiguration" Tid="34" Time="2012-04-26 10:04:10Z">
    Starting SCP lookup for domainName='sip.domain', root path='
    </Trace>
    =====================AutodiscoverConfiguration========================
    <Trace Tag="AutodiscoverConfiguration" Tid="34" Time="2012-04-26 10:04:10Z">
    Searching for SCP entries in LDAP://CN=Configuration,DC=parent,DC=domain
    </Trace>
    =====================AutodiscoverConfiguration========================
    <Trace Tag="AutodiscoverConfiguration" Tid="34" Time="2012-04-26 10:04:10Z">
    Scanning for SCP pointers Domain=sip.domain
    </Trace>
    =====================AutodiscoverConfiguration========================
    <Trace Tag="AutodiscoverConfiguration" Tid="34" Time="2012-04-26 10:04:10Z">
    No SCP pointers found for 'Domain=sip.domain' in configPath='CN=Configuration,DC=parent,DC=domain'
    </Trace>
    =====================AutodiscoverConfiguration========================
    <Trace Tag="AutodiscoverConfiguration" Tid="34" Time="2012-04-26 10:04:10Z">
    Scanning for SCP urls for the current computer Site=TEST
    </Trace>
    =====================AutodiscoverConfiguration========================
    <Trace Tag="AutodiscoverConfiguration" Tid="34" Time="2012-04-26 10:04:10Z">
    Adding (prio 1) 'https://webmail.domain/autodiscover/autodiscover.xml' for the 'Site=TEST' from 'LDAP://CN=FRSTM11MM1,CN=Autodiscover,CN=Protocols,CN=FRSTM11MM1,CN=Servers,CN=Exchange Administrative Group (FYDIBOHF23SPDLT),CN=Administrative Groups,CN=Test Systems,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=parent,DC=domain' to the top of the list (exact match)
    </Trace>

    Message: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index
       at System.Collections.ArrayList.get_Item(Int32 index)
       at System.DirectoryServices.ResultPropertyValueCollection.get_Item(Int32 index)
       at Microsoft.Exchange.WebServices.Autodiscover.DirectoryHelper.GetScpUrlList(String domainName, String ldapPath, Int32& maxHops)
       at Microsoft.Exchange.WebServices.Autodiscover.DirectoryHelper.GetAutodiscoverScpUrlsForDomain(String domainName)
       at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetAutodiscoverServiceUrls(String domainName, Int32& scpHostCount)
       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 SelfExchangeService.AutoDiscoverExchangeWebServices(String emailaddr) -- Priority: 0 --Severity: Critical--ProcessId: 2688--Win32 ThreadId:3360

    This looks like some error in server configuration. How is exception raised? Where to check the configurations?

    Thanks very much.


    Thursday, May 10, 2012 1:55 AM

All replies

  • What looks to happening is the SCP lookup in your domain is failing from the looks of it there is a record but no data which is an unexpected outcome (eg generally there will be something or nothing). You might want to have a read of http://johanveldhuis.nl/?page_id=1683&lang=en which goes through how to check to make sure your SCP records are setup in your forest and what you might need to do if you have multiple forests etc.

    If you have no control over this and just want to make your code work then i would suggest you make use of the Autodiscover classes and you can just disable the SCP lookup meaning that only a DNS discover will be done eg

             AutodiscoverService adAutoDiscoverSvc = new AutodiscoverService();
             adAutoDiscoverSvc.Credentials = new NetworkCredential("user@domain.com", "password");
             adAutoDiscoverSvc.EnableScpLookup = false;
             adAutoDiscoverSvc.RedirectionUrlValidationCallback = adAutoDiscoCallBack;
             GetUserSettingsResponse adResponse = adAutoDiscoverSvc.GetUserSettings("User@domain.com", (new UserSettingName[1] { UserSettingName.AlternateMailboxes }));
    
            private static bool adAutoDiscoCallBack(string url)
            {
                return true;
            }
    Cheers
    Glen
    Thursday, May 10, 2012 5:31 AM
  • Hello,

    We are using similar code described in the problem statement. In one of our environment autodiscoverurl is throwing the same exception(Index was out of range.).

    As per suggestion by Glen, we used the “AutodiscoverService” to suppress the SCP lookup. But at “GetUserSettings” function call, it is throwing an exception. Can anyone suggest what could be the issue.

    Is there any other way to find out the URL(like from Active Directory. If yes please point me in to the right direction) for specified email address.

    What things need to verify and resolve in the Exchange environment to resolve the issue(Exception thrown by AutodiscoverUrl “Index out of range” which reported in original question).

     

    Note: There is environment which works with  “exchangewebservice. AutodiscoverUrl”(original code without AutodiscoverService). But even in that environment “AutodiscoverService. GetUserSettings” throws an exception.

    Exception thrown by autodiscoverService.GetUserSettings(emailid,UserSettingName.ExternalEwsUrl):

       at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetSetting

    s[TGetSettingsResponseCollection,TSettingName](List`1 identities, List`1 setting

    s, Func`4 getSettingsMethod, Func`1 getDomainMethod)

       at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetUserSet

    tings(List`1 smtpAddresses, List`1 settings)

       at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetUserSet

    tings(String userSmtpAddress, UserSettingName[] userSettingNames)

    Thanks,

    Sandeep


    Sandeep Gupta

    Wednesday, May 20, 2015 1:59 PM
  • The Managed API is now open source https://github.com/OfficeDev/ews-managed-api so fork of your own Repo and then debug issue to see if you can find the bug in the code and implement your own fix or workaround. If its a fix consider submitting it for inclusion in the master repo

    Cheers
    Glen

    Thursday, May 21, 2015 3:23 AM