1

I received an exception message while trying to perform the following commands: The request failed. The underlying connection was closed: An unexpected error occurred on a receive.

The codes are meant to impersonate an email account and retrieve all the bookings or meetings that is associated to that person. However, when trying to cast FindAppointments, it throws an exception.

Not sure if anyone came across this issue before, any help is appreciated. Thanks!

Codes as followed:

        List<Booking> bookings = new List<Booking>();
        CalendarView calendarView = new CalendarView(startDateTime, endDateTime);
        FindItemsResults<Appointment> appointments = null;

        if (emails != null && emails.Count() > 0)
        {
            HashSet<String> uniqueBookings = new HashSet<String>();

            foreach (String email in emails)
            {
                try
                {
                    FolderId calendarFolderId = new FolderId(WellKnownFolderName.Calendar, email);
                    this.PortalExchangeService.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, email);
                    appointments = this.PortalExchangeService.FindAppointments(calendarFolderId, calendarView);  // this line throws an exception

                    .....
                }
                catch (System.Exception exception)
                {
                    logger.Error("RetrieveRoomBookingNoShow()");
                    logger.Error(exception.Message);
                    //  return null;
                }
            }
        }
5
  • Have you made any requests on the PortalExchangeService before calling FindAppointments()? IF not, the error could lay in how you create the service. Try make a simple call just to verify that the service is established correctly. Sep 28, 2016 at 5:52
  • What kind of simple call should i make to verify that the service is established correctly?
    – Shawn Ang
    Sep 28, 2016 at 7:11
  • Prior to that, I am able to find available rooms through a location.
    – Shawn Ang
    Sep 28, 2016 at 7:12
  • A simple call would be: var findFolderResults = PortalExchangeService.FindFolders(WellKnownFolderName.Root, new SearchFilter.IsGreaterThan(FolderSchema.TotalCount, 0), new FolderView(10)); But if you are able to find the rooms then the service should work. I have experinced the same error but in my case it hade nothing to do with the method I was calling, the exchange server just dropped my connection. I resolved this by recreating a new instance of the service every time the connection was lost. Sep 28, 2016 at 7:18
  • Btw: have you added PortalExchangeService.HttpHeaders.Add("X-AnchorMailbox", sExchangeEmail); PortalExchangeService.HttpHeaders.Add("X-PreferServerAffinity", "true"); Sep 28, 2016 at 7:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.