使用 Exchange 中的 EWS 更新约会和会议Update appointments and meetings by using EWS in Exchange

了解如何使用 Exchange 中的 EWS 托管 API 或 EWS 更新约会和会议。Learn how to update appointments and meetings by using the EWS Managed API or EWS in Exchange.

会议和约会之间的基本区别在于会议具有与会者,而约会则不是。The essential difference between meetings and appointments is that meetings have attendees, and appointments don't. 约会和会议既可以是单个实例,也可以是定期系列的一部分,但由于约会不包括与会者、会议室或资源,因此它们不需要发送邮件。Both appointments and meetings can be single instances or part of a recurring series, but because appointments don't include attendees, rooms, or resources, they do not require a message to be sent. 在内部,Exchange 对会议和约会使用相同的对象。Internally, Exchange uses the same object for both meetings and appointments. 您可以使用 EWS 托管 API约会类或 ews CalendarItem元素来处理会议和约会。You use the EWS Managed API Appointment class or the EWS CalendarItem element to work with meetings and appointments.

表1。用于更新约会和会议的 EWS 托管 API 方法和 EWS 操作Table 1. EWS Managed API method and EWS operations for updating appointments and meetings

EWS 托管的 API 方法EWS Managed API method 相应的 EWS 操作Corresponding EWS operations
约会。更新Appointment.Update
UpdateItemUpdateItem

UpdateItemResponseUpdateItemResponse

使用 EWS 托管 API 更新约会Update an appointment by using the EWS Managed API

下面的代码示例演示如何使用约会对象更新与约会关联的属性和update方法将约会保存到 "日历" 文件夹中。The following code example shows how to use the Appointment object to update properties associated with an appointment and the Update method to save the appointment to your calendar folder.

此示例假定您已通过 Exchange 服务器的身份验证,并获取了名为 "服务" 的ExchangeService对象。This example assumes that you have authenticated to an Exchange server and have acquired an ExchangeService object named service. 本地变量 appointmentId 是与现有约会相关联的标识符。The local variable appointmentId is an identifier associated with an existing appointment.

// Instantiate an appointment object by binding to it by using the ItemId.
// As a best practice, limit the properties returned to only the ones you need.
Appointment appointment = Appointment.Bind(service, appointmentId, new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End));
string oldSubject = appointment.Subject;
// Update properties on the appointment with a new subject, start time, and end time.
appointment.Subject = appointment.Subject + " moved one hour later and to the day after " + appointment.Start.DayOfWeek + "!";
appointment.Start.AddHours(25);
appointment.End.AddHours(25);
// Unless explicitly specified, the default is to use SendToAllAndSaveCopy.
// This can convert an appointment into a meeting. To avoid this,
// explicitly set SendToNone on non-meetings.
SendInvitationsOrCancellationsMode mode = appointment.IsMeeting ? 
    SendInvitationsOrCancellationsMode.SendToAllAndSaveCopy : SendInvitationsOrCancellationsMode.SendToNone;
// Send the update request to the Exchange server.
appointment.Update(ConflictResolutionMode.AlwaysOverwrite, mode);
// Verify the update.
Console.WriteLine("Subject for the appointment was \"" + oldSubject + "\". The new subject is \"" + appointment.Subject + "\"");

使用 EWS 更新约会Update an appointment by using EWS

以下示例中的请求和响应 XML 对应于在使用 Ews 托管 Api 更新约会的 EWS 托管 api 代码中进行的调用。The request and response XML in the following examples correspond to calls made by the EWS Managed API code in Update an appointment by using the EWS Managed API.

下面的示例演示使用UpdateItem操作更新约会时的请求 XML。The following example shows the request XML when you use the UpdateItem operation to update an appointment.

<?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="Exchange2007_SP1" />
    <t:TimeZoneContext>
      <t:TimeZoneDefinition Id="Pacific Standard Time" />
    </t:TimeZoneContext>
  </soap:Header>
  <soap:Body>
    <m:UpdateItem MessageDisposition="SaveOnly" ConflictResolution="AlwaysOverwrite" SendMeetingInvitationsOrCancellations="SendToNone">
      <m:ItemChanges>
        <t:ItemChange>
          <t:ItemId Id="AAMkA" ChangeKey="DwAAAB" />
          <t:Updates>
            <t:SetItemField>
              <t:FieldURI FieldURI="item:Subject" />
              <t:CalendarItem>
                <t:Subject>Tennis Lesson moved one hour later and to the day after Wednesday!</t:Subject>
              </t:CalendarItem>
            </t:SetItemField>
          </t:Updates>
        </t:ItemChange>
      </m:ItemChanges>
    </m:UpdateItem>
  </soap:Body>
</soap:Envelope>

下面的示例演示为响应UpdateItem请求而返回的 XML。The following example shows the XML that is returned in response to an UpdateItem request. 为了提高可读性, ItemIdChangeKey属性已缩短。The ItemId and ChangeKey attributes have been shortened for readability.

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="https://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <h:ServerVersionInfo MajorVersion="15" MinorVersion="0" MajorBuildNumber="815" MinorBuildNumber="6" Version="V2_7" 
 xmlns:h="https://schemas.microsoft.com/exchange/services/2006/types" xmlns="https://schemas.microsoft.com/exchange/services/2006/types" 
 xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
  </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="https://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="https://schemas.microsoft.com/exc
hange/services/2006/types">
      <m:ResponseMessages>
        <m:UpdateItemResponseMessage ResponseClass="Success">
          <m:ResponseCode>NoError</m:ResponseCode>
          <m:Items>
            <t:CalendarItem>
              <t:ItemId Id="AAMkA" ChangeKey="DwAAAB" />
            </t:CalendarItem>
          </m:Items>
          <m:ConflictResults>
            <t:Count>0</t:Count>
          </m:ConflictResults>
        </m:UpdateItemResponseMessage>
      </m:ResponseMessages>
    </m:UpdateItemResponse>
  </s:Body>
</s:Envelope>

使用 EWS 托管 API 更新会议Update a meeting by using the EWS Managed API

当您更新会议时,除了将已修改的约会项目保存到 "日历" 文件夹之外,您通常还需要向与会者发送更新的会议请求。When you update a meeting, in addition to saving the modified appointment item to the calendar folder, you also typically want to send updated meeting requests to attendees. 下面的代码示例演示如何更新会议和发送会议请求。The following code example shows how to update a meeting and send meeting requests.

此示例假定您已通过 Exchange 服务器的身份验证,并获取了名为 "服务" 的ExchangeService对象。This example assumes that you have authenticated to an Exchange server and have acquired an ExchangeService object named service. 本地变量 meetingId 是与现有约会相关联的标识符。The local variable meetingId is an identifier that is associated with an existing appointment.

// Instantiate an appointment object by binding to it using the ItemId.
// As a best practice, limit the properties returned to only the Appointment ID.
Appointment meeting = Appointment.Bind(service, meetingId, new PropertySet(AppointmentSchema.Subject, 
                                                                           AppointmentSchema.Location, 
                                                                           AppointmentSchema.RequiredAttendees, 
                                                                           AppointmentSchema.Resources));
string oldSubject = meeting.Subject;
// Update properties on the appointment with a new subject, location, an additional required attendee, and a resource.
meeting.Subject = "Team building exercise has moved!";
meeting.Location = "4567 Contoso Way, Redmond, OH 33333, USA";
meeting.RequiredAttendees.Add("alisa@contoso.com");
meeting.Resources.Add("dlpprojector@contoso.com");
// Send the update request to the Exchange server.
meeting.Update(ConflictResolutionMode.AlwaysOverwrite, SendInvitationsOrCancellationsMode.SendToAllAndSaveCopy);
// Verify the update.
Console.WriteLine("Subject for the meeting was \"" + oldSubject + "\". The new subject is \"" + meeting.Subject + "\"");

设置约会对象的属性后,将会议保存到 "日历" 文件夹,并使用Update方法发送更新的会议请求。After setting the properties on the Appointment object, save the meeting to your calendar folder and send updated meeting requests by using the Update method.

调用Update方法时,可以将两个枚举值之一作为参数传递:You can pass in one of two enumeration values as parameters when you call the Update method:

当您将ConflictResolutionMode枚举值设置为AlwaysOverwrite时,您的会议版本将始终保存到 "日历" 文件夹中。When you set the ConflictResolutionMode enumeration value to AlwaysOverwrite, your version of the meeting will always be saved to the calendar folder.

使用 EWS 更新会议Update a meeting by using EWS

以下示例中的请求和响应 XML 对应于通过使用 Ews 托管 Api 更新会议中的 EWS 托管 api 代码进行的调用。The request and response XML in the following examples correspond to calls made by the EWS Managed API code in Update a meeting by using the EWS Managed API.

下面的示例演示使用UpdateItem操作更新会议时的请求 XML。The following example shows the request XML when you use the UpdateItem operation to update a meeting.

<?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="Exchange2007_SP1" />
    <t:TimeZoneContext>
      <t:TimeZoneDefinition Id="Pacific Standard Time" />
    </t:TimeZoneContext>
  </soap:Header>
  <soap:Body>
    <m:UpdateItem MessageDisposition="SaveOnly" ConflictResolution="AlwaysOverwrite" SendMeetingInvitationsOrCancellations="SendToAllAndSaveCopy">
      <m:ItemChanges>
        <t:ItemChange>
          <t:ItemId Id="AAMkA" ChangeKey="DwAAA" />
          <t:Updates>
            <t:SetItemField>
              <t:FieldURI FieldURI="item:Subject" />
              <t:CalendarItem>
                <t:Subject>Team building exercise has moved!</t:Subject>
              </t:CalendarItem>
            </t:SetItemField>
            <t:SetItemField>
              <t:FieldURI FieldURI="calendar:Location" />
              <t:CalendarItem>
                <t:Location>4567 Contoso Way, Redmond, OH 33333, USA</t:Location>
              </t:CalendarItem>
            </t:SetItemField>
            <t:SetItemField>
              <t:FieldURI FieldURI="calendar:RequiredAttendees" />
              <t:CalendarItem>
                <t:RequiredAttendees>
                  <t:Attendee>
                    <t:Mailbox>
                      <t:Name>Mack.Chaves@contoso.com</t:Name>
                      <t:EmailAddress>Mack.Chaves@contoso.com</t:EmailAddress>
                      <t:RoutingType>SMTP</t:RoutingType>
                    </t:Mailbox>
                  </t:Attendee>
                  <t:Attendee>
                    <t:Mailbox>
                      <t:Name>Sadie.Daniels@contoso.com</t:Name>
                      <t:EmailAddress>Sadie.Daniels@contoso.com</t:EmailAddress>
                      <t:RoutingType>SMTP</t:RoutingType>
                    </t:Mailbox>
                  </t:Attendee>
                  <t:Attendee>
                    <t:Mailbox>
                      <t:EmailAddress>alisa@contoso.com</t:EmailAddress>
                    </t:Mailbox>
                  </t:Attendee>
                </t:RequiredAttendees>
              </t:CalendarItem>
            </t:SetItemField>
            <t:SetItemField>
              <t:FieldURI FieldURI="calendar:Resources" />
              <t:CalendarItem>
                <t:Resources>
                  <t:Attendee>
                    <t:Mailbox>
                      <t:EmailAddress>dlpprojector@contoso.com</t:EmailAddress>
                    </t:Mailbox>
                  </t:Attendee>
                </t:Resources>
              </t:CalendarItem>
            </t:SetItemField>
          </t:Updates>
        </t:ItemChange>
      </m:ItemChanges>
    </m:UpdateItem>
  </soap:Body>
</soap:Envelope>

下面的示例演示为响应UpdateItem请求而返回的 XML。The following example shows the XML that is returned in response to an UpdateItem request. 为了提高可读性, ChangeKeyItemId属性已缩短。The ChangeKey and ItemId attributes have been shortened for readability.

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="https://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <h:ServerVersionInfo MajorVersion="15" MinorVersion="0" MajorBuildNumber="815" MinorBuildNumber="6" Version="V2_7" 
 xmlns:h="https://schemas.microsoft.com/exchange/services/2006/types" 
 xmlns="https://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
  </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="https://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types">
      <m:ResponseMessages>
        <m:UpdateItemResponseMessage ResponseClass="Success">
          <m:ResponseCode>NoError</m:ResponseCode>
          <m:Items>
            <t:CalendarItem>
              <t:ItemId Id="AAMkA" ChangeKey="DwAAA" />
            </t:CalendarItem>
          </m:Items>
          <m:ConflictResults>
            <t:Count>0</t:Count>
          </m:ConflictResults>
        </m:UpdateItemResponseMessage>
      </m:ResponseMessages>
    </m:UpdateItemResponse>
  </s:Body>
</s:Envelope>

另请参阅See also