1

只是我希望每次有人添加新约会或对他/她所拥有的内容进行任何更改时都会收到通知。

我知道如何做到这一点的唯一方法是使用 service.SubscribeToStreamingNotifications 但这里的问题是它只侦听服务必须以这种方式喜欢的帐户

var service = new ExchangeService(ExchangeVersion.Exchange2010_SP2)
{
    Credentials = new WebCredentials(userName, password)
};

service.SubscribeToStreamingNotifications(new FolderId[]
{
    WellKnownFolderName.Calendar
}, EventType.FreeBusyChanged, EventType.Deleted);

我通过创建一个服务列表解决了这个问题,每个服务都绑定到不同的用户,应用程序应该监听它们中的每一个。

这种方式的问题是我需要拥有每个帐户的密码,我不会听它的事件,这在现实世界中是不可能的。

那么有什么办法可以解决这个问题吗?

4

2 回答 2

1

I have solved this problem, by creating a list of services, all the services are a clone of the main ExchangeService, with the same credentials for the admin account, but they are impersonated to the other accounts.

NOTE: You need to setup the server so it allows impersonation.

private void ImpersonateUsers(ICollection<string> userSmtps)
        {
            if (userSmtps != null)
                if (userSmtps.Count > 0)
                {
                    foreach (var userSmtp in userSmtps)
                    {
                        if (_services.ContainsKey(userSmtp)) continue;
                        var newService = new ExchangeService(ExchangeVersion.Exchange2010_SP2);

                        try
                        {
                            var serviceCred = ((System.Net.NetworkCredential)(((WebCredentials)(_services.First().Value.Credentials)).Credentials));
                            newService.Credentials = new WebCredentials(serviceCred.UserName, serviceCred.Password, serviceCred.Domain);
                            newService.AutodiscoverUrl(serviceCred.UserName + "@" + serviceCred.Domain, RedirectionUrlValidationCallback);
                            newService.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, userSmtp);
                        }
                        catch (Exception ex)
                        {
                            System.Diagnostics.Debug.WriteLine(ex.Message);
                        }
                        _services.Add(userSmtp, newService);
                    }
                }
        }

Where userSmtps is a list of the email addresses I want to impersonate and _services is the dictionary of services where the first member is the main service.

于 2012-08-01T08:28:25.093 回答
0

您必须为每个用户创建一个服务实例。无法订阅其他用户文件夹。

但是您也可以使用 Pull 和 Push-Subscriptions 来代替 StreamingNotifications。像这样的东西:

List<FolderId> folders = new List<FolderId>();
folders.Add(new FolderId(WellKnownFolderName.Calendar));
PullSubscription subscription = = service.SubscribeToPullNotifications(folders, 1440, watermark, EventType.Created, EventType.Deleted, EventType.Modified, EventType.Moved, EventType.NewMail);

一段时间以后....

GetEventsResults currentevents = m_subscription .GetEvents();
于 2012-07-16T14:45:07.820 回答