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 (29)

  1. Peter Olsson says:

    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

  2. Vikas - MSFT says:

    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

  3. Lien says:

    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

  4. Vikas - MSFT says:

    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

  5. Indranil Sen says:

    Hi,

    Can you tell me how to identify a mail read event??

    Thanks in advance

    ~Neil

  6. Vikas - MSFT says:

    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

  7. Saqib Mukri says:

    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

  8. Wei says:

    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

  9. ChrisLamont-Mankowski says:

    I’m looking for a list of ports used in EWS push/pull Notification…

  10. dex63 says:

    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.

  11. We had a customer recently who’s application iterated through mailboxes on the Exchange server, advising

  12. gel says:

    how do you keep the subscriber running all the time?

  13. Vikas - MSFT says:

    Hi All,

    Been quite some time I replied to comments on this post.. kinda lost the flow.. let me try to answer them now.

    @Saqib – There is no out_of_box solution to get a notification when you get a reply to the message you sent. Of course you can build your own logic and use notifications to get this information. Here is how I would do it… once the mail is sent, I will go to sent items and check its ConversationTopic and keep in memory. With every new email received I will compare the ConversationTopic and see if this is a reply to the original message sent.

    @Wei  – You cannot use EWS to list all the mailboxes, you need to use Exchange Powershell (Get-Mailbox) to list all the mailboxes.

    @Chris – EWS is based on HTTP(s) and the ports are used are 80/443 while sending/receiving  request/response. If you are using Push notification then you are connecting to Port 80/443 of server and server is sending response back to 80/443 of your web server where you are hosting your custom web service.

    @dex63 – I will post a code sample (in C#.net) sometime this weekend

    @Gel – Normally you will have three components in case of Push Notifications

    1) Exchange 2007 (EWS)

    2) Subscriber

    3) Events Receiver

    Subscriber & Events receiver can be same application depending upon your architecture. You may create two web services, one for subscribing to exchange and another to receive the notifications. Subscriber’s job is done once it subscribed to the exchange. It’s the receiver which needs to be ON all the time to get notifications and act upon them. Normally you will have receiver as your Web Service which is hosted under IIS and will be always ON by default.

    Happy Coding!!!

  14. Gel says:

    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?

  15. Vikas - MSFT says:

    @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

  16. Francesco Pace says:

    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…

  17. Ash says:

    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

  18. Eric says:

    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?

  19. svreddy.nitw says:

    Can I use EWS with MAPI ?

  20. Sara says:

    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)?

  21. dann says:

    I still didn’t find the link to the samples.

    Vikas, can you please post the link to the latest push notification samples?

    Thanks!

  22. Naveed Mazhar says:

    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.

  23. Kaiwalya Joshi says:

    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

  24. Kaiwalya Joshi says:

    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

  25. Vikas - MSFT says:

    @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

  26. Kaiwalya Joshi says:

    Thanks Vikas for your reply, It will definitely help me in my development.

  27. Jacky Chen says:

    Hi

    Why the subscriptionid returned in the responsemessage from ews of exchange 2007 sp1(or sp2) is not guid?

  28. mjb says:

    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….

  29. Victor Zahn says:

    Can Push Notification really be used in Exchange 2007?

    Bolg here says … Yes?

    In this overview here:

    msdn.microsoft.com/…/dd633678%28v=exchg.80%29.aspx

    It says yes (only stream notification is missing).

    But in the Method descriptions for the Push …

    msdn.microsoft.com/…/microsoft.exchange.webservices.data.exchangeservice.subscribetopushnotifications%28v=exchg.80%29.aspx

    It says "… starting with Exchange Server 2013."

    ???

    Is there Push for Exchange 2007 EWS?

    Is there maybe a working example?

Skip to main content