Obter compromissos e reuniões usando o EWS no Exchange
Saiba como obter compromissos e reuniões usando a API Gerenciada do EWS ou o EWS no Exchange.
Você pode recuperar compromissos e reuniões de uma pasta de calendário usando o método CalendarFolder.FindAppointments EWS Managed API ou a operação FindItem EWS.
Obter compromissos usando a API Gerenciada do EWS
O exemplo de código a seguir mostra como usar a API Gerenciada do EWS para recuperar compromissos de um usuário que estão entre um horário de início e término especificados.
// Initialize values for the start and end times, and the number of appointments to retrieve.
DateTime startDate = DateTime.Now;
DateTime endDate = startDate.AddDays(30);
const int NUM_APPTS = 5;
// Initialize the calendar folder object with only the folder ID.
CalendarFolder calendar = CalendarFolder.Bind(service, WellKnownFolderName.Calendar, new PropertySet());
// Set the start and end time and number of appointments to retrieve.
CalendarView cView = new CalendarView(startDate, endDate, NUM_APPTS);
// Limit the properties returned to the appointment's subject, start time, and end time.
cView.PropertySet = new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End);
// Retrieve a collection of appointments by using the calendar view.
FindItemsResults<Appointment> appointments = calendar.FindAppointments(cView);
Console.WriteLine("\nThe first " + NUM_APPTS + " appointments on your calendar from " + startDate.Date.ToShortDateString() +
" to " + endDate.Date.ToShortDateString() + " are: \n");
foreach (Appointment a in appointments)
{
Console.Write("Subject: " + a.Subject.ToString() + " ");
Console.Write("Start: " + a.Start.ToString() + " ");
Console.Write("End: " + a.End.ToString());
Console.WriteLine();
}
A seguir está a saída do exemplo de código.
The first five appointments on your calendar from 8/21/2013 to 9/20/2013 are:
Subject: Contoso devs team meeting Start: 8/21/2013 12:30:00 PM End: 8/21/2013 1:00:00 PM
Subject: Daily status meeting Start: 8/21/2013 1:00:00 PM End: 8/21/2013 2:00:00 PM
Subject: Lunch with sales team Start: 8/21/2013 2:30:00 PM End: 8/21/2013 3:30:00 PM
Subject: Tennis at the club Start: 8/22/2013 11:00:00 AM End: 8/22/2013 12:00:00 PM
Subject: Online training webcast: 8/22/2013 2:00:00 PM End: 8/22/2013 3:00:00 PM
Obter compromissos usando o EWS
O XML a seguir mostra uma solicitação de operação GetFolder para retornar uma ID de pasta para a operação FindItem .
<?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="https://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<t:RequestServerVersion Version="Exchange2007_SP1" />
</soap:Header>
<soap:Body>
<m:GetFolder>
<m:FolderShape>
<t:BaseShape>IdOnly</t:BaseShape>
</m:FolderShape>
<m:FolderIds>
<t:DistinguishedFolderId Id="calendar" />
</m:FolderIds>
</m:GetFolder>
</soap:Body>
</soap:Envelope>
O XML a seguir mostra a resposta GetFolder . Observe que os atributos FolderID e ChangeKey são abreviados para legibilidade.
<?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="731" MinorBuildNumber="10" Version="V2_3"
xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types"
xmlns="http://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:GetFolderResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<m:ResponseMessages>
<m:GetFolderResponseMessage ResponseClass="Success">
<m:ResponseCode>NoError</m:ResponseCode>
<m:Folders>
<t:CalendarFolder>
<t:FolderId Id="AAMk" ChangeKey="AgAA" />
</t:CalendarFolder>
</m:Folders>
</m:GetFolderResponseMessage>
</m:ResponseMessages>
</m:GetFolderResponse>
</s:Body>
</s:Envelope>
O XML a seguir mostra a solicitação FindItem usada para retornar os compromissos solicitados. Observe que os atributos FolderID e ChangeKey são abreviados para legibilidade.
<?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="https://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<t:RequestServerVersion Version="Exchange2007_SP1" />
</soap:Header>
<soap:Body>
<m:FindItem Traversal="Shallow">
<m:ItemShape>
<t:BaseShape>IdOnly</t:BaseShape>
<t:AdditionalProperties>
<t:FieldURI FieldURI="item:Subject" />
<t:FieldURI FieldURI="calendar:Start" />
<t:FieldURI FieldURI="calendar:End" />
</t:AdditionalProperties>
</m:ItemShape>
<m:CalendarView MaxEntriesReturned="5" StartDate="2013-08-21T17:30:24.127Z" EndDate="2013-09-20T17:30:24.127Z" />
<m:ParentFolderIds>
<t:FolderId Id="AAMk" ChangeKey="AgAA" />
</m:ParentFolderIds>
</m:FindItem>
</soap:Body>
</soap:Envelope>
O XML a seguir mostra a resposta FindItem . Observe que os atributos ItemID e ChangeKey são abreviados para legibilidade.
<?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="731" MinorBuildNumber="10" Version="V2_3"
xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types"
xmlns="http://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:FindItemResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<m:ResponseMessages>
<m:FindItemResponseMessage ResponseClass="Success">
<m:ResponseCode>NoError</m:ResponseCode>
<m:RootFolder TotalItemsInView="33" IncludesLastItemInRange="false">
<t:Items>
<t:CalendarItem>
<t:ItemId Id="AAMk" ChangeKey="DwAA" />
<t:Subject>Contoso devs team meeting</t:Subject>
<t:Start>2013-08-21T19:30:00Z</t:Start>
<t:End>2013-08-21T20:00:00Z</t:End>
</t:CalendarItem>
<t:CalendarItem>
<t:ItemId Id="AAMk" ChangeKey="DwAA" />
<t:Subject>Daily status meeting</t:Subject>
<t:Start>2013-08-21T20:00:00Z</t:Start>
<t:End>2013-08-21T21:00:00Z</t:End>
</t:CalendarItem>
<t:CalendarItem>
<t:ItemId Id="AAMk" ChangeKey="DwAA" />
<t:Subject>Lunch with sales team</t:Subject>
<t:Start>2013-08-21T21:30:00Z</t:Start>
<t:End>2013-08-21T22:30:00Z</t:End>
</t:CalendarItem>
<t:CalendarItem>
<t:ItemId Id="AAMk" ChangeKey="DwAA" />
<t:Subject>Tennis at the club</t:Subject>
<t:Start>2013-08-22T18:00:00Z</t:Start>
<t:End>2013-08-22T19:00:00Z</t:End>
</t:CalendarItem>
<t:CalendarItem>
<t:ItemId Id="AAMkA" ChangeKey="DwAA" />
<t:Subject>Online training webcast</t:Subject>
<t:Start>2013-08-22T21:00:00Z</t:Start>
<t:End>2013-08-22T22:00:00Z</t:End>
</t:CalendarItem>
</t:Items>
</m:RootFolder>
</m:FindItemResponseMessage>
</m:ResponseMessages>
</m:FindItemResponse>
</s:Body>
</s:Envelope>
Reuniões recorrentes e a exibição do calendário
A pasta calendário é um pouco diferente de outras pastas em uma caixa de correio porque ocorrências em uma série recorrente e exceções a uma série recorrente não são itens reais na caixa de correio, mas sim são armazenadas internamente como anexos a um mestre recorrente. Isso significa que, embora você possa criar uma solicitação EWS que retorna valores entre um conjunto de valores iniciais e finais usando um dos métodos de sobrecarga findItems da API Gerenciada do EWS, como ExchangeService.FindItems ou a operação EWS FindItem , o EWS não examinaria a tabela de anexo de cada item de calendário para encontrar exceções e ocorrências.
Em vez disso, o que você realmente deseja fazer é algo semelhante à aplicação de um Dataview em uma união de duas tabelas SQL, usando um objeto CalendarView . Observe que, por motivos de desempenho, recomendamos que você use a propriedade PropertySet para limitar o tamanho da resposta indicando o número de compromissos ou reuniões desejadas retornadas, bem como as propriedades específicas desejadas.