Partager via


Creating appointments and 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 create appointments and meetings.

Note

This topic covers the basic scenarios for creating appointments and meetings. Some advanced scenarios might require that you create appointments and meetings in specific time zones. For information about working with time zones in the EWS Managed API, see Time zones in the EWS Managed API 2.0 and Working with time zones by using the EWS Managed API 2.0.

To create an appointment

  1. Instantiate the Appointment object and identify the Exchange service. The following code shows how to create an appointment and provide it with connection configuration information by using an ExchangeService object named service.

    Appointment appointment = new Appointment(service);
    
  2. Set properties on the appointment. The following code shows how to add a subject, a body, a start time, and an end time to an appointment.

    appointment.Subject = "Dentist Appointment";
    appointment.Body = "The appointment is with Dr. Smith.";
    appointment.Start = new DateTime(2009, 3, 1, 9, 0, 0);
    appointment.End = appointment.Start.AddHours(2);
    
  3. Save the appointment. The following code shows how to save an appointment to the calendar.

    appointment.Save(SendInvitationsMode.SendToNone);
    

A meeting request is just an appointment with attendees.

To create a meeting and send a meeting request to invitees

  1. Instantiate the Appointment object and identify the Exchange service. The following code shows how to create an appointment and provide it with connection configuration information by using an ExchangeService object named service.

    Appointment appointment = new Appointment(service);
    
  2. Set properties on the appointment. The following code shows how to add a subject, a body, a start time, an end time, a location, two required attendees, and an optional attendee to an appointment. By adding attendees, you make this appointment a meeting.

    appointment.Subject = "Status Meeting";
    appointment.Body = "The purpose of this meeting is to discuss status.";
    appointment.Start = new DateTime(2009, 3, 1, 9, 0, 0);
    appointment.End = appointment.Start.AddHours(2);
    appointment.Location = "Conf Room";
    appointment.RequiredAttendees.Add("user1@contoso.com");
    appointment.RequiredAttendees.Add("user2@contoso.com");
    appointment.OptionalAttendees.Add("user3@contoso.com");
    
  3. Send the meeting request and save a copy. The following code shows how to send the meeting request to all attendees and save a copy of the meeting request to the Sent Items folder.

    appointment.Save(SendInvitationsMode.SendToAllAndSaveCopy);
    

The following table lists methods that you can use to save meeting requests, send meeting requests, or both.

Method name

Description

Save(SendInvitationsMode.SendToNone)

Use to save a meeting request to a default folder without sending invitations to attendees.

Save(SendInvitationsMode.SendOnlyToAll)

Use to send invitations to all attendees without saving a copy.

Save(SendInvitationsMode.SendToAllAndSaveCopy)

Use to send invitations to all attendees and save a copy of the meeting request to the Sent Items folder.

Save(FolderId, SendInvitationsMode.SendToNone)

Use to save a meeting request to a specified folder without sending invitations to attendees.

Save(FolderId, SendInvitationsMode.SendToAllAndSaveCopy)

Use to send invitations to all attendees and save a copy of the meeting request to a specified folder.

Save(WellKnownFolderName, SendInvitationsMode.SendToNone)

Use to save a meeting request to the specified default folder without sending invitations to attendees.

Save(WellKnownFolderName, SendInvitationsMode.SendToAllAndSaveCopy)

Use to send invitations to all attendees and save a copy of the meeting request to the specified default folder.

Example

Creating an appointment

The following code example shows how to create an appointment.

// Create the appointment.
Appointment appointment = new Appointment(service);

// Set properties on the appointment.
appointment.Subject = "Dentist Appointment";
appointment.Body = "The appointment is with Dr. Smith.";
appointment.Start = new DateTime(2009, 3, 1, 9, 0, 0);
appointment.End = appointment.Start.AddHours(2);

// Save the appointment.
appointment.Save(SendInvitationsMode.SendToNone);

The following example shows the XML that is sent by using the Save method.

<?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 SendMeetingInvitations="SendToNone">
         <m:Items>
            <t:CalendarItem>
               <t:Subject>Dentist Appointment</t:Subject>
               <t:Body BodyType="Text">The appointment is with Dr. Smith.</t:Body>
               <t:Start>2009-03-02T17:00:00Z</t:Start>
               <t:End>2009-03-02T19:00:00Z</t:End>
            </t:CalendarItem>
         </m:Items>
      </m:CreateItem>
   </soap:Body>
</soap:Envelope>

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

<?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>
                  <t:CalendarItem>
                     <t:ItemId Id="AAMkADk=" ChangeKey="DwAAAB" />
                  </t:CalendarItem>
               </m:Items>
            </m:CreateItemResponseMessage>
         </m:ResponseMessages>
      </m:CreateItemResponse>
   </soap:Body>
</soap:Envelope>

Creating a meeting and sending a meeting request to invitees

The following code example shows how to create a meeting and send a meeting request to invitees.

// Create the appointment.
Appointment appointment = new Appointment(service);

// Set properties on the appointment. Add two required attendees and one optional attendee.
appointment.Subject = "Status Meeting";
appointment.Body = "The purpose of this meeting is to discuss status.";
appointment.Start = new DateTime(2009, 3, 1, 9, 0, 0);
appointment.End = appointment.Start.AddHours(2);
appointment.Location = "Conf Room";
appointment.RequiredAttendees.Add("user1@contoso.com");
appointment.RequiredAttendees.Add("user2@contoso.com");
appointment.OptionalAttendees.Add("user3@contoso.com");

// Send the meeting request to all attendees and save a copy in the Sent Items folder.
appointment.Save(SendInvitationsMode.SendToAllAndSaveCopy);

The following example shows the XML that is sent by using the Save method.

<?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 SendMeetingInvitations="SendToAllAndSaveCopy">
         <m:Items>
            <t:CalendarItem>
               <t:Subject>Status Meeting</t:Subject>
               <t:Body BodyType="Text">The purpose of this meeting is to discuss project status.</t:Body>
               <t:Start>2009-03-01T17:00:00Z</t:Start>
               <t:End>2009-03-01T19:00:00Z</t:End>
               <t:Location>Conf Room</t:Location>
               <t:RequiredAttendees>
                  <t:Attendee>
                     <t:Mailbox>
                        <t:EmailAddress>user1@contoso.com</t:EmailAddress>
                     </t:Mailbox>
                  </t:Attendee>
                  <t:Attendee>
                     <t:Mailbox>
                        <t:EmailAddress>user2@contoso.com</t:EmailAddress>
                     </t:Mailbox>
                  </t:Attendee>
               </t:RequiredAttendees>
               <t:OptionalAttendees>
                  <t:Attendee>
                     <t:Mailbox>
                        <t:EmailAddress>user3@contoso.com</t:EmailAddress>
                     </t:Mailbox>
                  </t:Attendee>
               </t:OptionalAttendees>
            </t:CalendarItem>
         </m:Items>
      </m:CreateItem>
   </soap:Body>
</soap:Envelope>

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

<?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>
                  <t:CalendarItem>
                     <t:ItemId Id="AAMkA =" ChangeKey="DwAAA " />
                  </t:CalendarItem>
               </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.