Criar compromissos e reuniões usando o EWS no Exchange 2013Create appointments and meetings by using EWS in Exchange 2013

Saiba como criar compromissos e reuniões usando a API gerenciada do EWS ou o EWS no Exchange.Learn how to create appointments and meetings by using the EWS Managed API or EWS in Exchange.

A diferença essencial entre reuniões e compromissos é que as reuniões têm participantes e compromissos não.The essential difference between meetings and appointments is that meetings have attendees, and appointments don't. Compromissos e reuniões podem ser instâncias únicas ou parte de uma série recorrente, mas como os compromissos não incluem participantes, salas ou recursos, eles não exigem que uma mensagem seja enviada.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. Internamente, o Exchange usa o mesmo objeto para reuniões e compromissos.Internally, Exchange uses the same object for both meetings and appointments. Você usa a classe de compromisso da API gerenciada do EWS ou o elemento [CalendarItem](https://msdn.microsoft.com/library/Title Topic ID Project Name Writer Editor Publish Preview.aspx) do EWS para trabalhar com reuniões e compromissos.You use the EWS Managed API Appointment class or the EWS [CalendarItem](https://msdn.microsoft.com/library/Title Topic ID Project Name Writer Editor Publish Preview.aspx) element to work with meetings and appointments.

Tabela 1. Métodos da API gerenciada do EWS e operações do EWS para trabalhar com compromissos e reuniõesTable 1. EWS Managed API methods and EWS operations for working with appointments and meetings

Método de API gerenciada do EWSEWS Managed API method Operação do EWSEWS operation
Compromisso. SaveAppointment.Save
Operação CreateItem (item de calendário)CreateItem operation (calendar item)
Item. bindItem.Bind
Operação GetItem (item de calendário)GetItem operation (calendar item)

Criar um compromisso usando a API gerenciada do EWSCreate an appointment by using the EWS Managed API

O exemplo de código a seguir mostra como usar o objeto compromisso para criar um compromisso, o método Save para salvá-lo na pasta calendário e o método Item. bind para verificar se o compromisso foi criado.The following code example shows how to use the Appointment object to create an appointment, the Save method to save it to your calendar folder, and the Item.Bind method to verify that the appointment was created.

Este exemplo pressupõe que você tenha autenticado em um servidor do Exchange e tenha adquirido um objeto ExchangeService chamado Service.This example assumes that you have authenticated to an Exchange server and have acquired an ExchangeService object named service.

Appointment appointment = new Appointment(service);
// Set the properties on the appointment object to create the appointment.
appointment.Subject = "Tennis lesson";
appointment.Body = "Focus on backhand this week.";
appointment.Start = DateTime.Now.AddDays(2);
appointment.End = appointment.Start.AddHours(1);
appointment.Location = "Tennis club";
appointment.ReminderDueBy = DateTime.Now;
// Save the appointment to your calendar.
appointment.Save(SendInvitationsMode.SendToNone);
// Verify that the appointment was created by using the appointment's item ID.
Item item = Item.Bind(service, appointment.Id, new PropertySet(ItemSchema.Subject));
Console.WriteLine("\nAppointment created: " + item.Subject + "\n");

Após definir as propriedades no objeto compromisso, você salva o compromisso na pasta calendário usando o método Save do objeto compromisso.After setting the properties on the appointment object, you save the appointment to the calendar folder by using the appointment object's Save method.

Observe que, na etapa de verificação, você usa a ID do item associada ao compromisso para verificar se o compromisso está na pasta calendário.Note that in the verification step, you use the item Id associated with the appointment to verify that the appointment is in the calendar folder. Como prática recomendada, limite as propriedades retornadas pelo servidor para apenas o que você precisa — neste caso, o assunto do compromisso.As a best practice, limit the properties returned by the server to only what you need — in this case, the appointment's subject.

Criar um compromisso usando o EWSCreate an appointment by using EWS

O XML de solicitação e resposta nos exemplos a seguir correspondem a chamadas feitas pelo código da API gerenciada do EWS em criar um compromisso usando a API gerenciada do EWS.The request and response XML in the following examples correspond to calls made by the EWS Managed API code in Create an appointment by using the EWS Managed API. O XML de solicitação e resposta que verifica se os itens de compromisso estão na pasta calendário também são mostrados.The request and response XML that verifies that the appointment items are in the calendar folder are shown as well.

O exemplo a seguir mostra a solicitação de XML quando você usa a operação CreateItem para criar um compromisso.The following example shows the request XML when you use the CreateItem operation to create 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:CreateItem SendMeetingInvitations="SendToNone">
      <m:Items>
        <t:CalendarItem>
          <t:Subject>Tennis lesson</t:Subject>
          <t:Body BodyType="HTML">Focus on backhand this week.</t:Body>
          <t:ReminderDueBy>2013-09-19T14:37:10.732-07:00</t:ReminderDueBy>
          <t:Start>2013-09-21T19:00:00.000Z</t:Start>
          <t:End>2013-09-21T20:00:00.000Z</t:End>
          <t:Location>Tennis club</t:Location>
          <t:MeetingTimeZone TimeZoneName="Pacific Standard Time" />
        </t:CalendarItem>
      </m:Items>
    </m:CreateItem>
  </soap:Body>
</soap:Envelope>

O exemplo a seguir mostra a resposta XML retornada pela operação CreateItem .The following example shows the response XML that is returned by the CreateItem operation.

Observação

Os atributos ItemId e ChangeKey foram reduzidos para facilitar a leitura.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="775" MinorBuildNumber="7" Version="V2_4" 
 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:CreateItemResponse xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages" 
  xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types">
      <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>
  </s:Body>
</s:Envelope>

O exemplo a seguir mostra o XML Request que é gerado quando você usa a operação GetItem para verificar se o compromisso foi criado.The following example shows the request XML that is generated when you use the GetItem operation to verify that the appointment was created.

Observação

Os atributos ItemId e ChangeKey foram reduzidos para facilitar a leitura.The ItemId and ChangeKey attributes have been shortened for 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="Exchange2007_SP1" />
    <t:TimeZoneContext>
      <t:TimeZoneDefinition Id="Pacific Standard Time" />
    </t:TimeZoneContext>
  </soap:Header>
  <soap:Body>
    <m:GetItem>
      <m:ItemShape>
        <t:BaseShape>IdOnly</t:BaseShape>
        <t:AdditionalProperties>
          <t:FieldURI FieldURI="item:Subject" />
        </t:AdditionalProperties>
      </m:ItemShape>
      <m:ItemIds>
        <t:ItemId Id="AAMkA" ChangeKey="DwAAA" />
      </m:ItemIds>
    </m:GetItem>
  </soap:Body>
</soap:Envelope>

O exemplo a seguir mostra a resposta XML que é retornada pela operação GetItem .The following example shows the response XML that is returned by the GetItem operation.

Observação

Os atributos ItemId e ChangeKey foram reduzidos para facilitar a leitura.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="775" MinorBuildNumber="7" Version="V2_4" 
 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:GetItemResponse xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types">
      <m:ResponseMessages>
        <m:GetItemResponseMessage ResponseClass="Success">
          <m:ResponseCode>NoError</m:ResponseCode>
          <m:Items>
            <t:CalendarItem>
              <t:ItemId Id="AAMkA" ChangeKey="DwAAA" />
              <t:Subject>Tennis lesson</t:Subject>
            </t:CalendarItem>
          </m:Items>
        </m:GetItemResponseMessage>
      </m:ResponseMessages>
    </m:GetItemResponse>
  </s:Body>
</s:Envelope>

Criar uma reunião usando a API gerenciada do EWSCreate a meeting by using the EWS Managed API

Ao criar uma reunião, além de salvar um item na pasta calendário, normalmente você também deseja enviar solicitações de reunião para os participantes.When you create a meeting, in addition to saving an item to the calendar folder, you also typically want to send meeting requests to attendees. O exemplo de código a seguir mostra como criar uma reunião e enviar solicitações de reunião.The following code example shows how to create a meeting and send meeting requests.

Este exemplo pressupõe que você tenha autenticado em um servidor do Exchange e tenha adquirido um objeto ExchangeService chamado Service.This example assumes that you have authenticated to an Exchange server and have acquired an ExchangeService object named service.

Appointment meeting = new Appointment(service);
// Set the properties on the meeting object to create the meeting.
meeting.Subject = "Team building exercise";
meeting.Body = "Let's learn to really work as a team and then have lunch!";
meeting.Start = DateTime.Now.AddDays(2);            
meeting.End = meeting.Start.AddHours(4);
meeting.Location = "Conference Room 12";
meeting.RequiredAttendees.Add("Mack@contoso.com");
meeting.RequiredAttendees.Add("Sadie@contoso.com");
meeting.OptionalAttendees.Add("Magdalena@contoso.com");
meeting.ReminderMinutesBeforeStart = 60;
// Save the meeting to the Calendar folder and send the meeting request.
meeting.Save(SendInvitationsMode.SendToAllAndSaveCopy);
// Verify that the meeting was created.
Item item = Item.Bind(service, meeting.Id, new PropertySet(ItemSchema.Subject));
Console.WriteLine("\nMeeting created: " + item.Subject + "\n");

Após definir as propriedades no objeto de compromisso , salve a reunião em sua pasta de calendário usando o método Save .After setting the properties on the Appointment object, save the meeting to your calendar folder by using the Save method. Quando você define o valor de enumeração SendInvitationsMode como SendOnlyToAll ou SendToAllAndSaveCopy, os convites são enviados para os participantes.When you set the SendInvitationsMode enumeration value to SendOnlyToAll or SendToAllAndSaveCopy, invitations are sent to attendees.

Use a ID do item associada à reunião para verificar se ela foi salva na pasta calendário.Use the item Id associated with the meeting to verify that it was saved in the calendar folder. Como prática recomendada, limite as propriedades retornadas pelo servidor a apenas o que você precisa – nesse caso, o assunto da reunião.As a best practice, limit the properties returned by the server to only what you need - in this case, the meeting's subject.

Criar uma reunião usando o EWSCreate a meeting by using EWS

O XML de solicitação e resposta nos exemplos a seguir correspondem a chamadas feitas pelo código da API gerenciada do EWS em criar uma reunião usando a API gerenciada do EWS.The request and response XML in the following examples correspond to calls made by the EWS Managed API code in Create a meeting by using the EWS Managed API. O XML de solicitação e resposta que verifica se os itens da reunião estão na pasta calendário também são mostrados.The request and response XML that verifies that the meeting items are in the calendar folder are shown as well.

O exemplo a seguir mostra a solicitação de XML quando você usa a operação CreateItem para criar uma reunião.The following example shows the request XML when you use the CreateItem operation to create 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:CreateItem SendMeetingInvitations="SendToAllAndSaveCopy">
      <m:Items>
        <t:CalendarItem>
          <t:Subject>Team building exercise</t:Subject>
          <t:Body BodyType="HTML">Let's learn to really work as a team and then have lunch!</t:Body>
          <t:ReminderMinutesBeforeStart>60</t:ReminderMinutesBeforeStart>
          <t:Start>2013-09-21T16:00:00.000Z</t:Start>
          <t:End>2013-09-21T20:00:00.000Z</t:End>
          <t:Location>Conference Room 12</t:Location>
          <t:RequiredAttendees>
            <t:Attendee>
              <t:Mailbox>
                <t:EmailAddress>Mack.Chaves@contoso.com</t:EmailAddress>
              </t:Mailbox>
            </t:Attendee>
            <t:Attendee>
              <t:Mailbox>
                <t:EmailAddress>Sadie.Daniels@contoso.com</t:EmailAddress>
              </t:Mailbox>
            </t:Attendee>
          </t:RequiredAttendees>
          <t:OptionalAttendees>
            <t:Attendee>
              <t:Mailbox>
                <t:EmailAddress>Magdalena.Kemp@contoso.com</t:EmailAddress>
              </t:Mailbox>
            </t:Attendee>
          </t:OptionalAttendees>
          <t:MeetingTimeZone TimeZoneName="Pacific Standard Time" />
        </t:CalendarItem>
      </m:Items>
    </m:CreateItem>
  </soap:Body>
</soap:Envelope>

O exemplo a seguir mostra a resposta XML retornada pela operação CreateItem .The following example shows the response XML that is returned by the CreateItem operation.

Observação

Os atributos ItemId e ChangeKey foram reduzidos para facilitar a leitura.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="775" MinorBuildNumber="7" Version="V2_4" 
 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:CreateItemResponse xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types">
      <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>
  </s:Body>
</s:Envelope>

O exemplo a seguir mostra o XML de solicitação gerado pela operação GetItem quando você verifica se a reunião foi criada.The following example shows the request XML that is generated by the GetItem operation when you verify that the meeting was created.

Observação

Os atributos ItemId e ChangeKey foram reduzidos para facilitar a leitura.The ItemId and ChangeKey attributes have been shortened for 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="Exchange2007_SP1" />
    <t:TimeZoneContext>
      <t:TimeZoneDefinition Id="Pacific Standard Time" />
    </t:TimeZoneContext>
  </soap:Header>
  <soap:Body>
    <m:GetItem>
      <m:ItemShape>
        <t:BaseShape>IdOnly</t:BaseShape>
        <t:AdditionalProperties>
          <t:FieldURI FieldURI="item:Subject" />
        </t:AdditionalProperties>
      </m:ItemShape>
      <m:ItemIds>
        <t:ItemId Id="AAMkA" ChangeKey="DwAAA" />
      </m:ItemIds>
    </m:GetItem>
  </soap:Body>
</soap:Envelope>

O exemplo a seguir mostra a resposta XML que é retornada pela operação GetItem .The following example shows the response XML that is returned by the GetItem operation.

Observação

Os atributos ItemId e ChangeKey foram reduzidos para facilitar a leitura.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="775" MinorBuildNumber="7" Version="V2_4" 
 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:GetItemResponse xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types">
      <m:ResponseMessages>
        <m:GetItemResponseMessage ResponseClass="Success">
          <m:ResponseCode>NoError</m:ResponseCode>
          <m:Items>
            <t:CalendarItem>
              <t:ItemId Id="AAMkA" ChangeKey="DwAAA" />
              <t:Subject>Team building exercise</t:Subject>
            </t:CalendarItem>
          </m:Items>
        </m:GetItemResponseMessage>
      </m:ResponseMessages>
    </m:GetItemResponse>
  </s:Body>
</s:Envelope>

Confira tambémSee also