Deleting appointments and canceling meetings by using the EWS Managed API 2.0

Last modified: October 13, 2012

Applies to: EWS Managed API | Exchange Server 2007 Service Pack 1 (SP1) | Exchange Server 2010

Note: This content applies to the EWS Managed API 2.0 and earlier versions. For the latest information about the EWS Managed API, see Web services in Exchange.

You can use the Microsoft Exchange Web Services (EWS) Managed API to delete appointments and cancel meetings.

To delete an appointment

  1. Bind to an existing appointment by using its unique identifier. The following code shows how to bind to an existing appointment and provide it with connection configuration information by using an ExchangeService object named service. The ItemId has been shortened to preserve readability.

    Appointment appointment = Appointment.Bind(service, new ItemId("AAMkA="));
    
  2. Delete the appointment. The following code shows how to delete an appointment and move the deleted appointment to the Deleted Items folder.

    appointment.Delete(DeleteMode.MoveToDeletedItems);
    

To cancel a meeting

  1. Bind to an existing meeting request by using its unique identifier. The following code shows how to bind to an existing meeting request and provide it with connection configuration information by using an ExchangeService object named service. The ItemId has been shortened to preserve readability.

    Appointment appointment = Appointment.Bind(service, new ItemId("AAMkA="));
    
  2. Cancel the meeting. You can cancel a meeting by using the CancelMeeting method, the Delete method, or the CreateCancelMeetingMessage method.

    • The following code shows how to cancel a meeting by using the CancelMeeting method and send a generic cancellation message to all attendees.

      appointment.CancelMeeting();
      
    • The following code shows how to cancel a meeting by using the CancelMeeting method and send a customized cancellation message to all attendees.

      appointment.CancelMeeting("This meeting has been canceled due to poor weather.");
      
    • The following code shows how to cancel a meeting by using the Delete method. The meeting request is moved to the Deleted Items folder and a cancellation message is sent to all attendees.

      appointment.Delete(DeleteMode.MoveToDeletedItems, SendCancellationsMode.SendOnlyToAll);
      
    • The following code shows how to cancel a meeting by using the CreateCancelMeetingMessage method to create a customized cancellation message and to request a read receipt from recipients. The cancellation message is sent to all attendees and a copy of the cancellation message is saved in the sender's Sent Items folder.

      CancelMeetingMessage cancelMessage = appointment.CreateCancelMeetingMessage();
      cancelMessage.Body = new MessageBody("This meeting is being canceled due to poor weather.");
      cancelMessage.IsReadReceiptRequested = true;
      cancelMessage.SendAndSaveCopy();
      

Example

Deleting an appointment

The following code example shows how to delete an appointment and move the deleted appointment to the Deleted Items folder. This example assumes that service is a valid ExchangeService binding. The ItemId has been shortened to preserve readability.

// Bind to an existing appointment by using its unique identifier.
Appointment appointment = Appointment.Bind(service, new ItemId("AAMkA="));

// Delete the appointment and move the deleted appointment to the Deleted Items folder. 
appointment.Delete(DeleteMode.MoveToDeletedItems);

The following example shows the XML that is sent by using the Delete method. The ItemId and ChangeKey attributes have been shortened to preserve readability.

<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                   xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages" 
                   xmlns:t=https://schemas.microsoft.com/exchange/services/2006/types 
                   xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/">
   <soap:Header>
      <t:RequestServerVersion Version="Exchange2010" />
   </soap:Header>
   <soap:Body>
      <m:DeleteItem DeleteType="MoveToDeletedItems" SendMeetingCancellations="SendToAllAndSaveCopy">
         <m:ItemIds>
            <t:ItemId Id="AAMkA=" ChangeKey="DwAAA" />
         </m:ItemIds>
      </m:DeleteItem>
   </soap:Body>
</soap:Envelope>

The following example shows the XML that is returned by using the Delete method.

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/" 
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
               xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Header>
      <t:ServerVersionInfo MajorVersion="8" MinorVersion="1" MajorBuildNumber="344" MinorBuildNumber="0" Version="Exchange2010" xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types" />
   </soap:Header>
   <soap:Body>
      <m:DeleteItemResponse xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types" xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages">
         <m:ResponseMessages>
            <m:DeleteItemResponseMessage ResponseClass="Success">
               <m:ResponseCode>NoError</m:ResponseCode>
            </m:DeleteItemResponseMessage>
         </m:ResponseMessages>
      </m:DeleteItemResponse>
   </soap:Body>
</soap:Envelope>

Canceling a meeting

The following code example shows how to cancel a meeting and sends a customized cancellation message to all attendees. This example assumes that service is a valid ExchangeService binding. The ItemId has been shortened to preserve readability.

// Bind to an existing meeting request by using its unique identifier.
Appointment appointment = Appointment.Bind(service, new ItemId("AAMkA="));

// Cancel the meeting and send a customized cancellation message to all attendees. 
appointment.CancelMeeting("This meeting has been canceled due to poor weather.");

The following example shows the XML that is sent by using the CancelMeeting method. The ItemId and ChangeKey attributes have been shortened to preserve readability.

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
               xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages" 
               xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types" 
               xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/">
   <soap:Header>
      <t:RequestServerVersion Version="Exchange2010" />
   </soap:Header>
   <soap:Body>
      <m:CreateItem MessageDisposition="SendAndSaveCopy">
         <m:Items>
            <t:CancelCalendarItem>
               <t:ReferenceItemId Id="AAMkA=" ChangeKey="DwAAA" />
               <t:NewBodyContent BodyType="Text">This meeting has been canceled due to poor weather.</t:NewBodyContent>
            </t:CancelCalendarItem>
         </m:Items>
      </m:CreateItem>
   </soap:Body>
</soap:Envelope>

The following example shows the XML that is returned by using the CancelMeeting method.

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/" 
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
               xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Header>
      <t:ServerVersionInfo MajorVersion="8" MinorVersion="1" MajorBuildNumber="344" MinorBuildNumber="0" Version="Exchange2010" xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types" />
   </soap:Header>
   <soap:Body>
      <m:CreateItemResponse xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types" xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages">
         <m:ResponseMessages>
            <m:CreateItemResponseMessage ResponseClass="Success">
               <m:ResponseCode>NoError</m:ResponseCode>
               <m:Items />
            </m:CreateItemResponseMessage>
         </m:ResponseMessages>
      </m:CreateItemResponse>
   </soap:Body>
</soap:Envelope>

Compiling the code

For information about compiling this code, see Getting started with the EWS Managed API 2.0.

Robust programming

  • Write appropriate error handling code for common search errors.

  • Review the client request XML that is sent to the Exchange server.

  • Review the server response XML that is sent from the Exchange server.

  • Set the service binding as shown in Setting the Exchange service URL by using the EWS Managed API 2.0. Do not hard code URLs because if mailboxes move, they might be serviced by a different Client Access server. If the client cannot connect to the service, retry setting the binding by using the AutodiscoverUrl(String) method.

  • Set the target Exchange Web Services schema version by setting the requestedServerVersion parameter of the ExchangeService constructor. For more information, see Versioning EWS requests by using the EWS Managed API 2.0.

Security

  • Use HTTP with SSL for all communication between client and server.

  • Always validate the server certificate that is used for establishing the SSL connections. For more information, see Validating X509 certificates by using the EWS Managed API 2.0.

  • Do not include user names and passwords in trace files.

  • Verify that Autodiscover lookups that use HTTP GET to find an endpoint always prompt for user confirmation; otherwise, they should be blocked.