I am developing small EWS client. For initial testing I wrote simple code:
service = new ExchangeService(ExchangeVersion.Exchange2007_SP1); service.Credentials = new WebCredentials("user1@domain1.com", "password"); service.TraceEnabled = true; ServicePointManager.ServerCertificateValidationCallback = CertificateValidationCallBack; service.AutodiscoverUrl("user1@domain1.com");
I included CertificateValidationCallBack method from this MSDN page.
I have two Exchange servers. For one exchange server this code worked fine for sending a new email.
However on another server I got following exception:
The Autodiscover service could not be located 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 Microsoft.Exchange.WebServices.Data.ExchangeService.AutodiscoverUrl(String emailAddress) at EwsDctmSyncer.Test.Main(String[] args) in C:\ewswork\csws\EwsTest\EwsExp\Test.cs:line 21 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()
When I look at the traces on console, I found this main problem:
failed: WebException (The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.)
However I dont understand what could be wrong with this second instance of Exchange Server. Can anyone pin point what could be wrong. I am puzzled since to my knowledge both the instances are similarly configured.
Added full trace as a reply to this post.