0

I'm using the EWS Managed API to load appointments for a specific room resource, and publish it via WCF to be consumed by a tablet device.

I'd like to cancel the meeting room booking if the organizer doesn't perform a specific action after 15mins that the meeting is scheduled to start.

Because the tablet device only has the StoreId property to identify the event from, I implemented the following code:

public bool CancelMeeting(string appointmentId, string roomEmail)
    {
        try
        {
            var service = GetExchangeService();
            var ai = new AlternateId[1];
            ai[0] = new AlternateId();
            ai[0].UniqueId = appointmentId;
            ai[0].Format = IdFormat.HexEntryId;
            ai[0].Mailbox = roomEmail;
            ServiceResponseCollection<ConvertIdResponse> cvtresp = service.ConvertIds(ai, IdFormat.EwsId);
            var appointment = Appointment.Bind(service, ((AlternateId)cvtresp[0].ConvertedId).UniqueId);

            if (appointment.Resources.Count != 0)
                appointment.Resources.RemoveAt(0);

            appointment.Location = string.Empty;

            appointment.Save(SendInvitationsMode.SendOnlyToAll);
            return true;
        }
        catch (Exception ex)
        {
            return false;
        }
    }

However,

if (appointment.Resources.Count != 0)
    appointment.Resources.RemoveAt(0);

in this code appointment.Resources.Count is always 0. As per this post (Can't Retrieve Resources (rooms) from Exchange Web Services) you need to tell EWS to specifically include the Resources. How do you specify to include the resources when using Appointment.Bind?

Community
  • 1
  • 1
Marcel
  • 944
  • 2
  • 9
  • 29

1 Answers1

2

In much the same way as that post you linked. Create a property set with the AppointmentSchema.Resources property and pass it to the Bind method.

PropertySet includeResources = new PropertySet(BasePropertySet.FirstClassProperties, AppointmentSchema.Resources);
var appointment = Appointment.Bind(service, ((AlternateId)cvtresp[0].ConvertedId).UniqueId, includeResources);

UPDATE:

It looks like you're accessing the room's calendar, not the organizer. In the room's calendar you won't see the resources. Resources are only visible in the organizer's calendar. This is because they are implemented as BCC recipients. Also bear in mind that removing something from the room's copy of the appointment would not remove it from the appointment in anyone else's mailbox, so this probably isn't the best approach. Instead, you would want to decline the meeting, which would send a decline notice back to the organizer and remove the meeting from the room's calendar.

Jason Johnston
  • 17,194
  • 2
  • 20
  • 34
  • Appointment is returned (as with the code I posted in the original post) and the Resources enumeration still states "Enumeration yielded no results" – Marcel Feb 04 '15 at 10:36
  • I've also tried (as is suggested in this post: http://stackoverflow.com/questions/8904741/finditems-and-bindtoitems-give-inconsistent-results-for-emailmessage-sender) : service.LoadPropertiesForItems(new List { appointment }, includeResources); – Marcel Feb 04 '15 at 10:46
  • What version of Exchange Server are you using, and what version are you specifying when creating the ExchangeService object? – Jason Johnston Feb 04 '15 at 14:35
  • Exchange 2013, and I initiate my service like this: ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013); service.Credentials = new WebCredentials(Properties.Settings.Default.EwsUsername, Properties.Settings.Default.EwsPassword); service.AutodiscoverUrl(Properties.Settings.Default.EwsAutodiscoverUrl); – Marcel Feb 11 '15 at 07:12
  • 1
    Just dawned on me that you're accessing the room's calendar, not the organizer. I updated my answer. – Jason Johnston Feb 11 '15 at 15:44