20

I am trying to update an existing appointment but EWS is throwing "Set action is invalid for property.". I reviewed all values set to the appointment object, but I am unable to figure out the actual cause of this error.

Here is my code snippet:

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
service.Credentials = new WebCredentials("ews_calendar", PASSWORD, "acme");
service.Url = new Uri("https://acme.com/EWS/Exchange.asmx");
ImpersonatedUserId impUser = new ImpersonatedUserId();
service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "tin.tin@acme.com");

string itemId = "";
DateTime PreviousStartDate = new DateTime(2012, 04, 02, 18, 00, 00);
DateTime PreviousEndDate = new DateTime(2012, 04, 02, 18, 30, 00);
CalendarView calView = new CalendarView(PreviousStartDate, PreviousEndDate);
Appointment appointment = new Appointment(service);
try
{
    calView.PropertySet = new PropertySet(BasePropertySet.IdOnly, AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.IsRecurring, AppointmentSchema.AppointmentType);
    FindItemsResults<Appointment> findResults = service.FindAppointments(WellKnownFolderName.Calendar, calView);

    List<Item> items = new List<Item>();
    foreach (Appointment appt in findResults.Items)
    {
        appt.Load();
        items.Add(appt);
    }

    if (items.Count > 0)
    {
        service.LoadPropertiesForItems(items, PropertySet.FirstClassProperties);
        appointment = (Appointment) items[0];
        appointment.Load(new PropertySet(BasePropertySet.IdOnly, AppointmentSchema.Start, AppointmentSchema.ReminderDueBy, AppointmentSchema.End, AppointmentSchema.StartTimeZone, AppointmentSchema.EndTimeZone, AppointmentSchema.TimeZone));
    }

    appointment.RequiredAttendees.Add("tin.tin@acme.com");

    appointment.Start = new DateTime(2012, 04, 02, 18, 00, 0);
    appointment.End = new DateTime(2012, 04, 02, 18, 30, 0);

    // throwing exception here -- Set action is invalid for property.
    appointment.Update(ConflictResolutionMode.AlwaysOverwrite, SendInvitationsOrCancellationsMode.SendToAllAndSaveCopy);
}
catch (Exception ex)
{
    //
}

[UPDATE]
Interestingly if I comment RequiredAttendees property of appointment in above code, everything seems fine, but no notification email send out to existing attendees.

[UPDATE] This is only happening for appointments which are created using iCal

[UPDATE]

Request Xml:

POST https://acmemail.com/EWS/Exchange.asmx HTTP/1.1
Content-Type: text/xml; charset=utf-8
Accept: text/xml
User-Agent: ExchangeServicesClient/14.02.0051.000
Accept-Encoding: gzip,deflate
Host: acmemail.com
Cookie: exchangecookie=7d09b9f23afd4604bd17e3aa58aa8417
Content-Length: 2410
Expect: 100-continue
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <t:RequestServerVersion Version="Exchange2010_SP1" />
    <t:ExchangeImpersonation>
      <t:ConnectingSID>
        <t:PrincipalName>ews_test_user</t:PrincipalName>
      </t:ConnectingSID>
    </t:ExchangeImpersonation>
  </soap:Header>
  <soap:Body>
    <m:UpdateItem ConflictResolution="AlwaysOverwrite" SendMeetingInvitationsOrCancellations="SendOnlyToAll">
      <m:ItemChanges>
        <t:ItemChange>
          <t:ItemId Id="AAMkADJiMGQ4ZWFkLWE0ODYtNDEyMC1hYWZjLTQ1ZGMyZDIzM2VjNwBGAAAAAAD9u1KcpHbwQZAL98T9qOWmBwCvOn1fMRuFRKKSfl9h8ZjeAAAAoz9XAABZjjBc5hT0S7NHrduyqC0sAAUlvIcSAAA=" ChangeKey="DwAAABYAAABkzlk3d4yMS7uVVX+i+BnJAAAABLU2" />
          <t:Updates>
            <t:SetItemField>
              <t:FieldURI FieldURI="item:Body" />
              <t:CalendarItem>
                <t:Body BodyType="HTML">TEST 3</t:Body>
              </t:CalendarItem>
            </t:SetItemField>
            <t:SetItemField>
              <t:FieldURI FieldURI="calendar:RequiredAttendees" />
              <t:CalendarItem>
                <t:RequiredAttendees>
                  <t:Attendee>
                    <t:Mailbox>
                      <t:Name>Tin.Tin</t:Name>
                      <t:EmailAddress>Tin.Tin@acmegroup.com</t:EmailAddress>
                      <t:RoutingType>SMTP</t:RoutingType>
                      <t:MailboxType>Mailbox</t:MailboxType>
                    </t:Mailbox>
                  </t:Attendee>
                  <t:Attendee>
                    <t:Mailbox>
                      <t:Name>Tin.Tin</t:Name>
                      <t:EmailAddress>Tin.Tin@acmegroup.com</t:EmailAddress>
                      <t:RoutingType>SMTP</t:RoutingType>
                      <t:MailboxType>OneOff</t:MailboxType>
                    </t:Mailbox>
                  </t:Attendee>
                </t:RequiredAttendees>
              </t:CalendarItem>
            </t:SetItemField>
          </t:Updates>
        </t:ItemChange>
      </m:ItemChanges>
    </m:UpdateItem>
  </soap:Body>
</soap:Envelope>

Response Xml:

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Header>
        <h:ServerVersionInfo MajorVersion="14" MinorVersion="1" MajorBuildNumber="355" MinorBuildNumber="2" Version="Exchange2010_SP1" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"/>
    </s:Header>
    <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <m:UpdateItemResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
            <m:ResponseMessages>
                <m:UpdateItemResponseMessage ResponseClass="Error">
                    <m:MessageText>Set action is invalid for property.</m:MessageText>
                    <m:ResponseCode>ErrorInvalidPropertySet</m:ResponseCode>
                    <m:DescriptiveLinkKey>0</m:DescriptiveLinkKey>
                    <m:MessageXml>
                        <t:FieldURI FieldURI="calendar:RequiredAttendees"/></m:MessageXml>
                    <m:Items/>
                </m:UpdateItemResponseMessage>
            </m:ResponseMessages>
        </m:UpdateItemResponse>
    </s:Body>
</s:Envelope> 
Vanuan
  • 31,770
  • 10
  • 98
  • 102
Firoz Ansari
  • 2,505
  • 1
  • 23
  • 36
  • 1
    Firoz, have you found a solution? I have the same issue and the marked SilverNinja's answer doesn't help. – MikhailSP Jun 19 '15 at 09:23
  • Old post but maybe still someone lf answer: Only the organizer of a meeting can update it's values, so in this case you need to impersonate to the organizer if possible. – YvesR Mar 24 '17 at 10:33

1 Answers1

7

You need to add AppointmentSchema.RequiredAttendees to your PropertySet if you wish to modify it (RequiredAttendees.Add is setting the appointment schema property). You cannot modify a property that is not included in your PropertySet.

appointment.Load(new PropertySet(BasePropertySet.IdOnly, AppointmentSchema.Start, AppointmentSchema.ReminderDueBy, AppointmentSchema.End, AppointmentSchema.StartTimeZone, AppointmentSchema.EndTimeZone, AppointmentSchema.TimeZone, AppointmentSchema.RequiredAttendees));

After reviewing your response XML - it seems this issue is related to the AppointmentState. See this MSDN post for reference. The response XML does tell you the field that is failing to update (calendar:RequiredAttendees).

SliverNinja - MSFT
  • 31,051
  • 11
  • 110
  • 173
  • I added AppointmentSchema.RequiredAttendees to my PropertySet as you suggested, but still same error. Is it possible to know which property is causing this issue? "Set action is invalid for property" is very generic error message. – Firoz Ansari Apr 03 '12 at 16:56
  • I appreciate your help SliverNinja. I am bit new with EWS API. Can you help me to make changes in my code to address this issue. – Firoz Ansari Apr 04 '12 at 14:58
  • You are right. AppointmentState is 3 (which means it considering it as meeting participant). AppointmentState should be 1 for meeting owners. I am not sure how to set AppointmentState property as it is readonly for appointment object. I feel like I am somewhere near solution. – Firoz Ansari Apr 04 '12 at 15:19
  • 1
    I have the same issue. What was the final solution for this? – Asterius Mar 29 '16 at 18:42
  • Any suggestions for those, who generate XML above manually? When I'm not sending Attendees field, interestingly I get "Access is denied. Check credentials and try again." error. – zkvarz Feb 09 '17 at 19:23