Exchange Web 服务按唯一 ID 查找项目

Exchange Web Services find item by unique id

我是第一次使用 Microsoft Exchange Web 服务。我希望能够做到的是:

这些会议在 ASP.NET MVC 应用程序中创建并保存到 SQL 服务器数据库中。我只是希望将其与现场 Exchange 服务器集成。到目前为止,我可以使用以下代码创建我的会议:[​​=20=]

public static Task<string> CreateMeetingAsync(string from, List<string> to, string subject, string body, string location, DateTime begin, DateTime end)
{
    var tcs = new TaskCompletionSource<string>();

    try
    {
        ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013);
        service.Credentials = CredentialCache.DefaultNetworkCredentials;
        //service.UseDefaultCredentials = true;

        // I suspect the Service URL needs to be set from the user email address because this is then used to set the organiser
        // of the appointment constructed below. The Organizer is a read-only field that cannot be manually set. (security measure)
        service.AutodiscoverUrl(from);
        //service.Url = new Uri(WebConfigurationManager.AppSettings["ExchangeServer"]);

        Appointment meeting = new Appointment(service);

        meeting.Subject = subject;
        meeting.Body = "<span style=\"font-family:'Century Gothic'\" >" + body + "</span><br/><br/><br/>";
        meeting.Body.BodyType = BodyType.HTML;
        meeting.Start = begin;
        meeting.End = end;
        meeting.Location = location;
        meeting.ReminderMinutesBeforeStart = 60;

        foreach (string attendee in to)
        {
            meeting.RequiredAttendees.Add(attendee);
        }
        meeting.Save(SendInvitationsMode.SendToAllAndSaveCopy);
        tcs.TrySetResult(meeting.Id.UniqueId);
    }
    catch (Exception ex)
    {
        tcs.TrySetException(ex);
    }

    return tcs.Task;
}

这成功地创建了我的会议,将其放入 outlook 中的用户日历中,并向所有与会者发送会议请求。我在尝试调用 meeting.Save(SendInvitationsMode.SendToAllAndSaveCopy); 两次时注意到以下异常:

This operation can't be performed because this service object already has an ID. To update this service object, use the Update() method instead.

我想:太棒了,它保存了项目以换取一个唯一的 id。我会将此 ID 保存在我的应用程序的数据库中,稍后在 edit/cancel 会议中使用它。这就是为什么我 return id: tcs.TrySetResult(meeting.Id.UniqueId);

这很好地保存到我的应用程序的数据库中:

现在,我正在尝试执行更新会议的下一部分,但我无法找到一种方法来根据我保存的唯一标识符搜索项目。我在 code.msdn 上找到的一个示例使用 service.FindItems() 方法和搜索主题的查询:

string querystring = "Subject:Lunch";
FindItemsResults<Item> results = service.FindItems(WellKnownFolderName.Calendar, querystring, view); 

我不喜欢这样。用户有可能在我的应用程序之外创建了一个碰巧具有相同主题的会议,这是我的应用程序并取消它。我试图确定是否可以在查询字符串中使用唯一 ID,但这似乎 possible.

我确实在上面的查询字符串页面上注意到,您可以搜索的最后一个 属性 是在 "all word phase properties." 中搜索的(属性 未指定)。因此,我尝试将 id 简单地放入查询中,但是 returns 没有结果:

FindItemsResults<Item> results = service.FindItems(WellKnownFolderName.Calendar, "AAMkADJhZDQzZWFmLWYxYTktNGI1Yi1iZTA5LWVmOTE3MmJiMGIxZgBGAAAAAAAqhOzrXRdvRoA6yPu9S/XnBwDXvBDBMebkTqUWix3HxZrnAAAA2LKLAAB5iS34oLxkSJIUht/+h9J1AAFlEVLAAAA=", view);

使用Appointment.Bind静态函数,提供服务object和保存在数据库中的ItemId。请注意会议工作流程(邀请、接受、拒绝)可以 re-create 在具有新 ItemId 的同一日历上召开会议。但是,如果您只是查看自己在日历上安排的会议,应该没问题。