Welcome to MSDN Blogs Sign in | Join | Help

Jive into Messaging world

Bridging the gap

News

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

Posted: Tuesday, August 28, 2007 9:53 PM by Vikas Verma

Comments

Peter Olsson said:

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

# August 30, 2007 5:12 AM

Vikas Verma said:

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

# August 30, 2007 10:02 PM

Lien said:

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

# February 6, 2008 3:17 AM

Vikas Verma said:

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

# February 6, 2008 9:27 AM

Indranil Sen said:

Hi,

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

Thanks in advance

~Neil

# July 7, 2008 9:29 AM

Vikas Verma said:

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

# July 10, 2008 3:43 PM

Saqib Mukri said:

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

# December 19, 2008 5:36 AM

Wei said:

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

# January 6, 2009 10:37 AM

ChrisLamont-Mankowski said:

I'm looking for a list of ports used in EWS push/pull Notification...

# January 6, 2009 4:32 PM

dex63 said:

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.

# February 3, 2009 6:56 PM

SGriffin's MAPI Internals said:

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

# February 19, 2009 9:45 AM

gel said:

how do you keep the subscriber running all the time?

# April 3, 2009 3:55 AM

Vikas Verma said:

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!!!

# April 3, 2009 10:17 AM

Gel said:

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?

# April 5, 2009 11:44 PM

Vikas Verma said:

@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

# April 30, 2009 10:41 AM

Francesco Pace said:

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

# September 15, 2009 1:35 PM

Ash said:

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

# October 9, 2009 7:45 AM

Eric said:

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?

# October 21, 2009 12:34 PM

svreddy.nitw said:

Can I use EWS with MAPI ?

# December 2, 2009 9:45 AM

Sara said:

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

# December 4, 2009 10:17 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

  
Enter Code Here: Required

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker