Share via


EWS: Exchange 2007 Notification Subsystem

Exchange Web Service in Exchange 2007 contains an Event Notification subsystem, which notifies the client & server applications of events that occur in mailboxes on Exchange 2007 server. Clients can subscribe to this notification subsystem and specify the kind of events they want to be notified for.

Exchange Web Service for Exchange 2007 supports two types of notifications:

  • Pull Notification
  • Push Notification

EWS notification clients can be classified in two categories, loosely coupled & tightly coupled

Loosely coupled clients are

  • connected to EWS through firewall and/or multiple networks
  • not IP Addressable, exchange server cannot resolve them via their IP address
  • their network connection to server is not reliable

Tightly coupled client

  • exists in the same network as the Exchange Server
  • IP Addressable

Note: You can decide the type of notification you want to use on the basis of your requirements, although it is more appropriate to use Pull Notification for loosely coupled clients while Push Notification works best with tightly coupled clients.

 For Pull Notification, clients subscribe for events they want to be notified of, and then periodically check for the accumulated notifications from the CAS (Client Access server). CAS does not automatically notify the client for any event occurred on the server and client needs to re-establish the connection with server whenever they want the changes on server.

The story is different with Push Notification, client need not to periodically request for changes occurred on server. Client subscribe for the particular events and also provide a callback point (web service), which can be called upon by the CAS in case of any change occurred, for which client registered, on server. Generally, push notifications provide less notification latency than pull notification. Servers those can host web service, and have a static IP or DNS name, are served best by push notifications. The web service can then process and redistribute notifications as needed to their clients.

Pull Notification

Exchange Web Services provides a pull subscription so that client applications can discover events that occur in the Exchange store. Using pull subscriptions involves the following three basic steps:

· Creating a subscription

· Retrieving store events

· Ending the subscription

Creating a pull subscription

· Create a new Subscribe request.

· Identify the folders to monitor for events.

· Identify the events to monitor for the subscription.

· Define the timeout period for the subscription.

· Send the Subscribe request and receive the Subscribe response. The Subscribe response includes the Subscription ID and the initial watermark that is used for the first GetEvents call.

Retrieving store events

· Create a new GetEvents request.

· Use the SubscriptionId returned in the subscribe response. For the first GetEvents request, use the watermark returned in the subscribe response. For subsequent GetEvents requests, use the last watermark returned in the previous GetEvents request.

· Send the GetEvents request and receive the GetEvents response. Each GetEvents response includes information about one or more events. A watermark is returned for each event. The last watermark must be saved and used in the next GetEvents request.

Note: If no store events have occurred since the last GetEvents request, a status event is returned

Ending the subscription

· Create an Unsubscribe request.

· Identify the subscription to unsubscribe from.

· Send the Unsubscribe request and receive the Unsubscribe response.

Note: A subscription is also deleted if a GetEvents request is not made within the timeout period. The timeout period is specified when the subscription is created with the Subscribe Operation.

Q & A

Q. What is a Watermark?

A. Watermark act as bookmark and gives you an idea what all events have been fired since last watermark. Every time you ask for changes using GetEvents, exchange will give you a list of changes occurred till that time and also a Watermark for that time. Next time you call GetEvents you pass this watermark to the server asking for any event occurred after that watermark. If there were new events then server will give you those events and a new watermark. Upon receiving the new watermark you can update your database to reflect the latest watermark.

Q. How will I update my watermark?

A. As already answered, every time you call GetEvents you receive a new watermark representing the events till the time you last called GetEvents. You can replace the previous watermark with this new watermark.

Q. Do I need one watermark for each change (appointment)?

A. No, you need one watermark per subscription. That subscription will receive all the notifications for all the appointments.

Q. Are there issues to consider in terms of maintaining many pull subscriptions simultaneously?

A. AFAIK there is no known issue and you should be fine with many subscriptions simultaneously.

Q. Will the subscription return events for changes made to appointment details including add/edit/delete of appointment and its attachments?

A. Yes, while subscribing you pass the information what all events you are interested in. You can select from the following events

· Mail arrival

· Item creation

· Item deletion

· Item modification

· Item movement

· Item copied

· Mail submission

Item modification should be fired upon adding/removing any attachments. I will once again confirm this for you.

Q. Can I restart my Pull notification client application?

A. Yes, you can restart your application. Next time you start your application you can re-use the last watermark to re-subscribe for events.

Keywords: Exchange Web Services, Exchange 2007, Notification, Pull Notification, Push Notification

Comments

  • Anonymous
    August 29, 2007
    Hi, I look forward for some examples! Right now we're developing a solution to receive push notifications from all user's calendars. I want to use this information to replicate all appointments to a separate system. We've already done this with event sinks for Exchange 2000 and 2003 - but now we're doing it for Exchange 2007, by using the the new Web Services. Mostly beacuse the earlier solution is made in Delphi, and it's not possible to build 64-bit applications in Delphi yet. The problem we have right now is that the documentation seem to be quite poor, and we can't find all the information we need to know. For instance, if a subscription will "live" forever, or if we need to re-register once in a while, and if we do - how can we be 100% sure that we did not miss a notification before we re-registered? When using event sinks we could be 100% sure, but with push notifications we don't know anymore... I'd sure appreciate some examples about this, abouy how we're supposed to handle this... Regards, Peter Olsson

  • Anonymous
    August 30, 2007
    Peter, I will surely update few EWS samples soon including Push/Pull Notifications. To replicate appointments you can also use SyncFolderItems operation of EWS, see more about SyncFolderItems at http://msdn2.microsoft.com/en-us/library/aa563967.aspx It is a good move in a long run to use EWS to replace Event Sinks. Its lots more, from EWS point of view, to come with upcoming Service Packs of Exchange 2007. To clear your point regarding subscription duration, a Push Subscription should stay alive as long as you are responding to the events & status events it sends with an OK response and as long as the service remains running on the server. If the server goes down for some reason specifically if the w3wp.exe process is recycled you will need to re-create your subscription using the last Watermark you received from the server. As long as events are being generated a push subscription will basically relay them to you instantly (or as instantly as resources on the server allow). When no events are firing on your subscription, the server will send your client a “poll” according to the interval you specified in the StatusFrequency when you created the Push Subscription. A good guide is that if you haven’t received a “poll” from the server for a length of time equal to twice the StatusFrequency, then it is a good bet the Subscription has gone away for some reason and you should re-subscribe. I can understand that sometime it’s difficult to find a proper documentation and completely agree to that there is not complete documentation available, but complete and accurate is a goal impossible to achieve. We need support & feedback from people like you to make things better. Regards -Vikas

  • Anonymous
    February 05, 2008
    Hi, We are developing a Message synchronization bridge which synchronizes between exchange and a separate system for various data. we need notifications for all users mailboxes in exchange. is it possible using the admin account or impersonation. Since our solution is linux based we want to develop it in pure C++ and using EWS. kindly provide some samples for push notification. ~Lien

  • Anonymous
    February 06, 2008
    Hi Lien, I will soon post the samples, you can surely use impersonation for Notifications Read this for more information about impersonation in Exchange Web Services Configuring Exchange Impersonation (Exchange Web Services) http://msdn2.microsoft.com/en-us/library/bb204095.aspx Using Exchange Impersonation (Exchange Web Services) http://msdn2.microsoft.com/en-us/library/bb204088.aspx

  • Anonymous
    July 07, 2008
    Hi, Can you tell me how to identify a mail read event?? Thanks in advance ~Neil

  • Anonymous
    July 10, 2008
    Neil, There is no direct method which will tell you if the item has been read. You need to listen for the NotificationEventTypeType.ModifiedEvent and check the IsRead flag of the item and update your existing items accordingly. Thanks, Vikas

  • Anonymous
    December 18, 2008
    Hi Vikas, Can I get a notification informing me that the mail you ahve sent using EWS is replied???? If not can you please provide me some different way as to how I can get a notification to one of my sent emails. Thanks in advance. -Saqib Mukri

  • Anonymous
    January 06, 2009
    Hi Vikas, Could you please let me know if you have the sample code in C# to use EWS impersonation for pull Notifications to get all users mailboxes in exchange store. Thanks. Wei

  • Anonymous
    January 06, 2009
    I'm looking for a list of ports used in EWS push/pull Notification...

  • Anonymous
    February 03, 2009
    Could you give detail instructions (sample code will be the best)on how to set up the push notification for all mailbox events using one/single account/impersonation?  We are building a similar applications like Lien mentioned above in Java. You response to Lien's question sounds it is feasible to have a single account to listen for all mailbox notifications. I did not find a concrete document on how to set this up. Thanks.

  • Anonymous
    February 19, 2009
    We had a customer recently who’s application iterated through mailboxes on the Exchange server, advising

  • Anonymous
    April 02, 2009
    how do you keep the subscriber running all the time?

  • Anonymous
    April 03, 2009
    The comment has been removed

  • Anonymous
    April 05, 2009
    I have publish the SDK sample PushNotificationClient and run the PushNotificationSubscriber... What's next? I'm totally lost... How can I check if the PushNotificationClient is being called by CAS?

  • Anonymous
    April 30, 2009
    @Gel - Sorry for replying late, can you please put some logging in your PushNotificationClient to see if it was called... may be log to some file or attach a debugger to it. Also, you can try to check the exchange server's event logs to see if there were any error while sending the push notifications to the client

  • Anonymous
    September 15, 2009
    How can I correlate a createItem request (EWS) with a notiicationResponse (Push Notification)? Is there some field that can avoid a loop on my client? I check every single attribute but no one can help me. ChangeKey doesn't work...

  • Anonymous
    October 08, 2009
    Hi Vikas, If the Push Notification Client Web Serice is configured with SSL certificate, how does Exchange Server handles SSL certificates? Are there any limitations for this requirement? When I tried with an SSL certificate which is applied on my Push Notification Client, I could not get any notification from Exchange Server for my Web Service. But it works perfectly fine when I remove the certificate. Thanks, Ash

  • Anonymous
    October 21, 2009
    What are the Exchange limitations as to how many subscriptions a CAS server can handle from a single source?  Would this limitation be any different using push versus the pull method?

  • Anonymous
    December 02, 2009
    Can I use EWS with MAPI ?

  • Anonymous
    December 04, 2009
    Hello!  Thanks for this informative article- how can I actually view a subscription and change where it goes?  Do you have any info on diagnosing and solving issues with this server (example- events 5, 6, 7)?

  • Anonymous
    February 25, 2010
    I still didn't find the link to the samples. Vikas, can you please post the link to the latest push notification samples? Thanks!

  • Anonymous
    April 27, 2010
    I want to use Push notifications for exchange server 2007. I am newbie in this. I want a step by step guide in achieving the target. I am using C# in my web application.

  • Anonymous
    August 26, 2010
    Hi Vikas, Currently we are developing application which will check appointment deleted and modified events, for doing this currently we are subscribing for each users appointment events. But for this we credentials of every user, is there any way e.b we can subscribe for administrator's appointment event and get the events of all the users that come this administrator. (we are currently using Push notifications.) Eagerly waiting for your response. Thanks and Regards, Kaiwalya

  • Anonymous
    August 26, 2010
    Hi Vikas, Currently we are developing application which will check appointment deleted and modified events, for doing this currently we are subscribing for each users appointment events. But for this we need credentials of every user, is there any way e.g we can subscribe for administrator's appointment events and get the appointment events of all the users that come under this administrator. (we are currently using Push notifications.) Eagerly waiting for your response. Thanks and Regards, Kaiwalya

  • Anonymous
    August 26, 2010
    @Kaiwalya You can do that by using Exchange Impersonation and listen to events in Calendar folder for multiple users, see this example on how to subscribe to multiple users folders blogs.msdn.com/.../howto-create-search-folder-using-exchange-impersonation-for-multiple-users-via-exchange-web-services.aspx Read this to get information from other users mailbox, again using Impersonation blogs.msdn.com/.../howto-ews-get-oof-state-for-self-or-any-user-in-your-organization.aspx

  • Anonymous
    August 30, 2010
    Thanks Vikas for your reply, It will definitely help me in my development.

  • Anonymous
    September 12, 2011
    Hi Why the subscriptionid returned in the responsemessage from ews of exchange 2007 sp1(or sp2) is not guid?

  • Anonymous
    July 13, 2014
    A couple of things I've never seen clearly enunciated

  1. What happens if a subscription has timed out? Is the watermark gone (I see some info claiming it lasts 30 days). Does an error get returned in this case?
  2. If I subscribe in one process, and need to resume getEvents in another process, say an hour later, there is no resumeSubscriptions call, there is only beginSubscribe (in the managed api). And that only takes a watermark, not a subscriptionID....