Since moving our Exchange installation to Office 365 the ExchangeService.AutodiscoverUrl (from within EWSConnectionManger.ConnectToEWS) call have started to fail. I get the following exception:
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.GetAutodiscoverServiceHosts(String domainName, Int32& scpHostCount)
at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetSettings[TGetSettingsResponseCollection,TSettingName](List1 identities, List1 settings, Nullable1 requestedVersion, GetSettingsMethod2 getSettingsMethod, Func1 getDomainMethod) at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetUserSettings(List1 smtpAddresses, List1 settings) at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetSoapUserSettings(String smtpAddress, List1 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 Mail2Bug.Email.EWS.EWSConnectionManger.ConnectToEWS(Credentials credentials, Boolean useConversationGuidOnly) in C:\Projects\GitHub\mail2bug\Mail2Bug\Email\EWS\EWSConnectionManger.cs:line 91
at Mail2Bug.Email.EWS.EWSConnectionManger.GetConnection(Credentials credentials, Boolean useConversationGuidOnly) in C:\Projects\GitHub\mail2bug\Mail2Bug\Email\EWS\EWSConnectionManger.cs:line 61
at Mail2Bug.Email.MailboxManagerFactory.CreateMailboxManager(EmailSettings emailSettings) in C:\Projects\GitHub\mail2bug\Mail2Bug\Email\MailboxManagerFactory.cs:line 31
at Mail2Bug.Mail2BugEngine..ctor(InstanceConfig configInstance, MailboxManagerFactory mailboxManagerFactory) in C:\Projects\GitHub\mail2bug\Mail2Bug\Mail2BugEngine.cs:line 31
at Mail2Bug.MainApp.InitInstances(IEnumerable`1 configs) in C:\Projects\GitHub\mail2bug\Mail2Bug\Main.cs:line 214
I can replicate this by newing up a ExchangeService and calling AutodiscoverUrl outside Mail2Bug.
If I use the Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService class instead, then I can get the URL to the mailbox, which I can use to set the ExchangeService.Url property and this works.
Would it be possible to have a setting which specifies that the AutodiscoverService class should be used instead of the AutodiscoverUrl method?
Since moving our Exchange installation to Office 365 the ExchangeService.AutodiscoverUrl (from within EWSConnectionManger.ConnectToEWS) call have started to fail. I get the following exception:
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.GetAutodiscoverServiceHosts(String domainName, Int32& scpHostCount) at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetSettings[TGetSettingsResponseCollection,TSettingName](List
1 identities, List
1 settings, Nullable1 requestedVersion, GetSettingsMethod
2 getSettingsMethod, Func1 getDomainMethod) at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetUserSettings(List
1 smtpAddresses, List1 settings) at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetSoapUserSettings(String smtpAddress, 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 Mail2Bug.Email.EWS.EWSConnectionManger.ConnectToEWS(Credentials credentials, Boolean useConversationGuidOnly) in C:\Projects\GitHub\mail2bug\Mail2Bug\Email\EWS\EWSConnectionManger.cs:line 91 at Mail2Bug.Email.EWS.EWSConnectionManger.GetConnection(Credentials credentials, Boolean useConversationGuidOnly) in C:\Projects\GitHub\mail2bug\Mail2Bug\Email\EWS\EWSConnectionManger.cs:line 61 at Mail2Bug.Email.MailboxManagerFactory.CreateMailboxManager(EmailSettings emailSettings) in C:\Projects\GitHub\mail2bug\Mail2Bug\Email\MailboxManagerFactory.cs:line 31 at Mail2Bug.Mail2BugEngine..ctor(InstanceConfig configInstance, MailboxManagerFactory mailboxManagerFactory) in C:\Projects\GitHub\mail2bug\Mail2Bug\Mail2BugEngine.cs:line 31 at Mail2Bug.MainApp.InitInstances(IEnumerable`1 configs) in C:\Projects\GitHub\mail2bug\Mail2Bug\Main.cs:line 214I can replicate this by newing up a ExchangeService and calling AutodiscoverUrl outside Mail2Bug.
If I use the Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService class instead, then I can get the URL to the mailbox, which I can use to set the ExchangeService.Url property and this works.
Would it be possible to have a setting which specifies that the AutodiscoverService class should be used instead of the AutodiscoverUrl method?