Click here to Skip to main content
15,306,676 members
Articles / Desktop Programming / Windows Forms
Posted 3 Nov 2007


19 bookmarked

Exchange 2007 Push Notifications Using WCF

Rate me:
Please Sign up or sign in to vote.
2.78/5 (6 votes)
3 Nov 2007Ms-PL3 min read
Consuming Exchange 2007 Push notifications using WCF.


Exchange 2007 introduced a new programming model by using Web Services. The API is called Exchange Web Services (EWS). The new programming model is easy to use, has a nice documentation in the SDK, and also a nice learning curve.


Notification is an event raised when a specific activity occurs to a specific resource in Exchange. The most obvious situation is when you want to monitor a specific mail box. Exchange has two methods of notification; passive and active notifications:

  1. Pull Notifications (Passive approach): You build your application so that it asks Exchange every specific period of time about any events occurred to the desired resource.
  2. Push Notifications (Active approach): Exchange will notify you about changes that has occurred and sends the notification to your application via a custom Web Service (a web service that you built).

Either of these (Pull or Push) notifications requires you to subscribe to the required events so that Exchange can generate the desired notifications which will be sent to your application.

EWS Programming and Types

EWS differentiates between two types of resource folders and items. An item could be a message, contact, task, etc… So, the notification in this sample monitors the Inbox folder.

Programming against EWS is done by Request and Response.

You create the (Request). Then, using ExchangeBindingService, you send the request and return the (Response) which you test for success.


The Push notification sample included in the SDK has a subscriber project and a client web service project to consume the Exchange notifications.

Thinking that you may not have IIS installed or that you have to build a web service to have a bridge between your application and the Exchange notifications made me uncomfortable about the situation. EWS uses SOAP messages all the time. So, I figured out that using a WCF service will be a nice feature to interact with the notifications. WCF services could be hosted in any application, and it will integrate with the rest of the pieces in your software.


The Push notification client has Interfaces.cs which is generated from NotificationServices.wsdl included in the SDK. To regenerate the same file, you have to borrow the Messages.XSD and Types.XSD from the Exchange folder in the server.

Wsdl /si NotificationService.wsdl Messages.xsd Types.xsd

But to generate WCF code, you need to run svcutil.

Svcutil NotificationServices.wsdl Messages.xsd Types.xsd

Your class will inherit the class generated in

public class Notification : NotificationServicePortType

NotificationServicePortType is different than the class in Interfaces.cs in the sample, but don't panic; it is a wrapper to the desired type. WCF will handle all the issues once we adjust the EndPoint configuration.

Running the Demo

You should be aware that your WCF could be running on another computer.

  • You should add exceptions in the Windows firewall for the chosen port or disable the firewall.
  • Refer to the computer names if Exchange and the WCF service are in separate machines; else use localhost.
  • Make sure that the /EWS folder exists in IIS and that its website is running, and make sure of the port it uses.
  • A lot of errors will be related to the URLs most of the time.

How WCF Acts like a Web Service

The EndPoint configurations have to be configured accurately to make the WCF act like a Web Service and to let the Exchange call the SendNotification method correctly.

See this part in the App.config file:

<endpoint address=""           


  • Version 1.0.


This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


About the Author

Ahmed Sadek
Engineer Lost Particles Network
Egypt Egypt
No Biography provided

Comments and Discussions

Questionit used to work years ago Pin
rosone2-Feb-12 4:58
Memberrosone2-Feb-12 4:58 
QuestionWhat about Exchange 2010 version? Pin
JamesQ30-Sep-10 16:40
MemberJamesQ30-Sep-10 16:40 
AnswerRe: What about Exchange 2010 version? Pin
thepsion12-Jan-11 22:16
Memberthepsion12-Jan-11 22:16 
QuestionHow do I get the subject of the new email Pin
rowmark24-May-10 4:18
Memberrowmark24-May-10 4:18 
QuestionHow to get mail item Pin
Shahzad.Aslam17-May-10 0:33
MemberShahzad.Aslam17-May-10 0:33 
AnswerRe: How to get mail item Pin
rowmark24-May-10 15:07
Memberrowmark24-May-10 15:07 
GeneralRe: How to get mail item Pin
Shahzad.Aslam24-May-10 19:11
MemberShahzad.Aslam24-May-10 19:11 
GeneralRe: How to get mail item Pin
rowmark25-May-10 4:08
Memberrowmark25-May-10 4:08 
GeneralRe: How to get mail item Pin
Max Mendel26-May-10 7:29
MemberMax Mendel26-May-10 7:29 
GeneralRe: How to get mail item Pin
Shahzad.Aslam26-May-10 18:50
MemberShahzad.Aslam26-May-10 18:50 
GeneralRe: How to get mail item Pin
rowmark3-Jun-10 5:58
Memberrowmark3-Jun-10 5:58 
GeneralRe: How to get mail item Pin
rowmark3-Jun-10 5:50
Memberrowmark3-Jun-10 5:50 
GeneralGetting error in opening host Pin
Shahzad.Aslam29-Apr-10 21:49
MemberShahzad.Aslam29-Apr-10 21:49 
GeneralException While Subscribing to PushNotification Pin
Rajendra Kondapalli18-Apr-10 20:38
MemberRajendra Kondapalli18-Apr-10 20:38 
QuestionException on running the sample program Pin
brahan_k_v15-Sep-09 2:29
Memberbrahan_k_v15-Sep-09 2:29 
AnswerRe: Exception on running the sample program Pin
gkriggs5-May-10 8:40
Membergkriggs5-May-10 8:40 
GeneralNo source code Pin
davidbitton4-May-09 9:03
Memberdavidbitton4-May-09 9:03 
GeneralNot getting notification for subscribed events. Pin
vacmkrishh23-Oct-08 2:00
Membervacmkrishh23-Oct-08 2:00 
QuestionWhy two projects? Pin
ReeY8-Aug-08 0:05
MemberReeY8-Aug-08 0:05 
QuestionWCF not getting events for the subscripton Pin
Neil@iCope24-Mar-08 21:19
MemberNeil@iCope24-Mar-08 21:19 
GeneralRe: WCF not getting events for the subscripton Pin
Ahmed Sadek25-Mar-08 13:54
MemberAhmed Sadek25-Mar-08 13:54 
GeneralRe: WCF not getting events for the subscripton Pin
rowmark24-May-10 15:09
Memberrowmark24-May-10 15:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.