What Exchange settings need to be checked to throw a ServiceRequestException?

Programmatically (using Microsoft Exchange Web Services Managed API 2.0) to access users' calendar (in Exchange 2010 SP1).

We were able to successfully communicate with EWS using auto-discovery in our development environment, where we didn't need to set any specific settings (we used the default settings) on Exchange.

Unfortunately, the same does not work in the client environment. The client does not have a test environment. They were supposed to communicate with their Exchange server.

Initially, auto-discovery did not work in the client environment. We got the following error:

Microsoft.Exchange.WebServices.Data.AutodiscoverLocalException: The Autodiscover service couldn't 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)

      

So now we are explicitly specifying the EWS url. This gave us the following error:

Microsoft.Exchange.WebServices.Data.ServiceRequestException: The request failed. The remote server returned an error: (401) Unauthorized. ---> System.Net.WebException: The remote server returned an error: (401) Unauthorized.
       at System.Net.HttpWebRequest.GetResponse()
       at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(HttpWebRequest request)
       --- End of inner exception stack trace ---
       at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(HttpWebRequest request)
       at Microsoft.Exchange.WebServices.Data.SimpleServiceRequestBase.InternalExecute()
       at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute()
       at Microsoft.Exchange.WebServices.Data.ExchangeService.BindToFolder(FolderId folderId, PropertySet propertySet)
       at Microsoft.Exchange.WebServices.Data.ExchangeService.BindToFolder[TFolder](FolderId folderId, PropertySet propertySet)
       at Microsoft.Exchange.WebServices.Data.CalendarFolder.Bind(ExchangeService service, FolderId id)

      

An exception is thrown on line 5 of the following code:

ServicePointManager.ServerCertificateValidationCallback = this.CertificateValidationCallBack;
ExchangeService exchangeWebService = new ExchangeService(ExchangeVersion.Exchange2010_SP1);

exchangeWebService.Credentials = new WebCredentials("username@domain.local", "myPassword");
exchangeWebService.AutodiscoverUrl("username@domain.local", this.RedirectionUrlValidationCallback);

**CalendarFolder calendarFolder = CalendarFolder.Bind(exchangeWebService, new FolderId(WellKnownFolderName.Calendar, userName));**

CalendarView calendarView = new CalendarView(startDate, endDate);
calendarView.PropertySet = new PropertySet(BasePropertySet.IdOnly, AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.IsRecurring, AppointmentSchema.AppointmentType, AppointmentSchema.End, AppointmentSchema.Duration);

FindItemsResults<Appointment> findResults = calendarFolder.FindAppointments(calendarView);

      

We don't mind auto-detection not working as we can explicitly specify the EWS url. We would like to know what settings, permissions, etc. We need to check on the Exchange client instance to determine why the exception (ServiceRequestException) was thrown.

We requested the following commands to run in the Exchange Management Shell on the Exchange client instance:

Test-OutlookWebServices –Identity username
Get-OrganizationConfig

      

We have yet to get results. Please let us know if there is anything else we need to check.

+3


source to share


2 answers


We knew the client had a proxy address. We didn't know that when calling AutodiscoverUrl and accessing the mailbox, we needed to use the domain address ( username@domain.local ) when authenticating with the EWS and proxy address ( username@domain.com ).

So the above code should be:

ServicePointManager.ServerCertificateValidationCallback = this.CertificateValidationCallBack;
ExchangeService exchangeWebService = new ExchangeService(ExchangeVersion.Exchange2010_SP1);

exchangeWebService.Credentials = new WebCredentials("username@domain.local", "myPassword");
exchangeWebService.AutodiscoverUrl("username@domain.com", this.RedirectionUrlValidationCallback);

CalendarFolder calendarFolder = CalendarFolder.Bind(exchangeWebService, new FolderId(WellKnownFolderName.Calendar, "username@domain.com"));

      



We used either a domain address or a proxy address. We never tried the above combination until we accidentally forgot to change the number on line # 3 of the above code. :)

Thanks to everyone who looked at the question and tried to answer it. Hope this helps someone someday.

+7


source


I recommend that you enable tracing to achieve this:

 Service.TraceEnabled = true;

      

I faced the same problem, then when I enable tracing, these traces will tell you exactly what is going on. In my case the SSL certificate problem is to solve it and then follow the post



There may be many questions such as:

  • The user can be blocked.

  • DSN cannot find autodiscover.domain.com

+2


source







All Articles