Notifications 流化通知不适用于Office 365/Exchange Online
我开发了一个小型控制台应用程序来测试EWS流化订阅/通知。在过去,我们使用推送通知,但从理论上讲,当使用StreamingNotifications时,我应该能够避免创建侦听器http端点及其所有问题(防火墙等) 所以,从我的本地机器;我正在这样做:Notifications 流化通知不适用于Office 365/Exchange Online,notifications,exchange-server,exchangewebservices,office365,ews-managed-api,Notifications,Exchange Server,Exchangewebservices,Office365,Ews Managed Api,我开发了一个小型控制台应用程序来测试EWS流化订阅/通知。在过去,我们使用推送通知,但从理论上讲,当使用StreamingNotifications时,我应该能够避免创建侦听器http端点及其所有问题(防火墙等) 所以,从我的本地机器;我正在这样做: static void Main(string[] args) { if (String.IsNullOrEmpty(ConfigurationManager.AppSettings["PrimaryLabUserId"])
static void Main(string[] args)
{
if (String.IsNullOrEmpty(ConfigurationManager.AppSettings["PrimaryLabUserId"]))
{
throw new ArgumentNullException("Please provide a value for PrimaryLabUserId in app.config");
}
_primaryLabUserId = ConfigurationManager.AppSettings["PrimaryLabUserId"];
string ServiceAccountName = ConfigurationManager.AppSettings["ExchangeServiceAccountName"];
string ServiceAccountPassword = ConfigurationManager.AppSettings["ExchangeServiceAccountPassword"];
_service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
_service.Credentials = new WebCredentials(ServiceAccountName, ServiceAccountPassword);
_service.AutodiscoverUrl(_primaryLabUserId, (x) => true);
_ewsUrl = _service.Url.AbsoluteUri;
var _connection = new StreamingSubscriptionConnection(_service, 30);
var sub = SubscribeForStreamingNotifications();
_connection.AddSubscription(sub);
_connection.OnDisconnect +=
new StreamingSubscriptionConnection.SubscriptionErrorDelegate(OnDisconnect);
// set up subscriptions here.
_connection.OnNotificationEvent +=
new StreamingSubscriptionConnection.NotificationEventDelegate(OnNewMail);
_connection.Open();
Console.WriteLine("Listening streaming...");
Console.ReadLine();
}
public static StreamingSubscription SubscribeForStreamingNotifications()
{
var folderIds = new List<FolderId>()
{
WellKnownFolderName.Inbox,
WellKnownFolderName.Calendar
};
var eventTypes = new List<EventType>();
eventTypes.Add(EventType.NewMail);
eventTypes.Add(EventType.Deleted);
eventTypes.Add(EventType.Moved);
eventTypes.Add(EventType.Created);
eventTypes.Add(EventType.Modified);
return _service.SubscribeToStreamingNotifications(folderIds, eventTypes.ToArray());
}
private static void OnNewMail(object sender, NotificationEventArgs args)
{
var test = args;
Console.WriteLine("Incoming");
}
static void Main(字符串[]args)
{
if(String.IsNullOrEmpty(ConfigurationManager.AppSettings[“PrimaryLabUserId”]))
{
抛出新ArgumentNullException(“请在app.config中为PrimaryLabUserId提供一个值”);
}
_primaryLabUserId=ConfigurationManager.AppSettings[“primaryLabUserId”];
字符串ServiceAccountName=ConfigurationManager.AppSettings[“ExchangeServiceAccountName”];
字符串ServiceAccountPassword=ConfigurationManager.AppSettings[“ExchangeServiceAccountPassword”];
_服务=新的ExchangeService(ExchangeVersion.Exchange2010_SP2);
_service.Credentials=新的WebCredentials(ServiceAccountName、ServiceAccountPassword);
_自动发现URL(_primaryLabUserId,(x)=>true);
_ewsUrl=_service.Url.AbsoluteUri;
var _connection=newstreamingsubscriptionconnection(_服务,30);
var sub=subscribefforstreamingnotifications();
_连接。添加订阅(sub);
_连接+=
新建StreamingSubscriptionConnection.SubscriptionErrorDelegate(OnDisconnect);
//在此处设置订阅。
_connection.OnNotificationEvent+=
新建StreamingSubscriptionConnection.NotificationEventDelegate(OnNewMail);
_connection.Open();
Console.WriteLine(“监听流…”);
Console.ReadLine();
}
public static StreamingSubscription SubscribeForStreamingNotifications()
{
var folderIds=新列表()
{
WellKnownFolderName.Inbox,
WellKnownFolderName.日历
};
var eventTypes=新列表();
添加(EventType.NewMail);
添加(EventType.Deleted);
添加(EventType.Moved);
添加(EventType.Created);
添加(EventType.Modified);
return _service.SubscribeToStreamingNotifications(folderId,eventTypes.ToArray());
}
私有静态void OnNewMail(对象发送方,NotificationEventArgs args args)
{
var检验=args;
控制台写入线(“传入”);
}
订阅初始化为OK,但当我向LabUser发送新邮件时,什么也没有发生。通知事件从不激发。我在pushnotifications上也尝试了同样的方法,但效果良好(在另一台服务器上,有一个公共http端点供exchange回调)。
我想知道这是否与我本地的机器有关。我真是太蠢了。我忘了冒充。由于我使用服务帐户呼叫EWS,它当然会监听该帐户的邮箱,除非您指定:
_service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, _primaryLabUserId);