Click here to Skip to main content
15,879,326 members
Articles / Desktop Programming / Windows Forms

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 84.9K   1.5K   19   22
Consuming Exchange 2007 Push notifications using WCF.

Introduction

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.

Notifications

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.

Motivation

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.

Notes

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 schemas.microsoft.com.exchange.services.2006.messages.cs.

C#
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:

XML
<endpoint address=""           
  contract="NotificationServicePortType" 
  binding="basicHttpBinding"
  bindingName="NotificationServiceBinding"
  bindingNamespace="http://schemas.microsoft.com/exchange/services/2006/messages"
/>

History

  • Version 1.0.

License

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


Written By
Engineer Lost Particles Network
Egypt Egypt
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Questionit used to work years ago Pin
rosone2-Feb-12 4:58
rosone2-Feb-12 4:58 
QuestionWhat about Exchange 2010 version? Pin
JamesQ30-Sep-10 16:40
JamesQ30-Sep-10 16:40 
AnswerRe: What about Exchange 2010 version? Pin
thepsion12-Jan-11 22:16
thepsion12-Jan-11 22:16 
QuestionHow do I get the subject of the new email Pin
rowmark24-May-10 4:18
rowmark24-May-10 4:18 
QuestionHow to get mail item Pin
Shahzad.Aslam17-May-10 0:33
Shahzad.Aslam17-May-10 0:33 
AnswerRe: How to get mail item Pin
rowmark24-May-10 15:07
rowmark24-May-10 15:07 
Shahzad,
Were you able to get it to work? I am also trying to do exactly the same thing but got stuck.
When I run the program it shows the eventname as NewemailEvent but not the actual message.

Do let me know if you got it to work?
GeneralRe: How to get mail item Pin
Shahzad.Aslam24-May-10 19:11
Shahzad.Aslam24-May-10 19:11 
GeneralRe: How to get mail item Pin
rowmark25-May-10 4:08
rowmark25-May-10 4:08 
GeneralRe: How to get mail item Pin
Max Mendel26-May-10 7:29
Max Mendel26-May-10 7:29 
GeneralRe: How to get mail item Pin
Shahzad.Aslam26-May-10 18:50
Shahzad.Aslam26-May-10 18:50 
GeneralRe: How to get mail item Pin
rowmark3-Jun-10 5:58
rowmark3-Jun-10 5:58 
GeneralRe: How to get mail item Pin
rowmark3-Jun-10 5:50
rowmark3-Jun-10 5:50 
GeneralGetting error in opening host Pin
Shahzad.Aslam29-Apr-10 21:49
Shahzad.Aslam29-Apr-10 21:49 
GeneralException While Subscribing to PushNotification Pin
Rajendra Kondapalli18-Apr-10 20:38
Rajendra Kondapalli18-Apr-10 20:38 
QuestionException on running the sample program Pin
brahan_k_v15-Sep-09 2:29
brahan_k_v15-Sep-09 2:29 
AnswerRe: Exception on running the sample program Pin
gkriggs5-May-10 8:40
gkriggs5-May-10 8:40 
GeneralNo source code Pin
davidbitton4-May-09 9:03
davidbitton4-May-09 9:03 
GeneralNot getting notification for subscribed events. Pin
vacmkrishh23-Oct-08 2:00
vacmkrishh23-Oct-08 2:00 
QuestionWhy two projects? Pin
ReeY8-Aug-08 0:05
ReeY8-Aug-08 0:05 
QuestionWCF not getting events for the subscripton Pin
Neil@iCope24-Mar-08 21:19
Neil@iCope24-Mar-08 21:19 
GeneralRe: WCF not getting events for the subscripton Pin
Ahmed Sadek25-Mar-08 13:54
Ahmed Sadek25-Mar-08 13:54 
GeneralRe: WCF not getting events for the subscripton Pin
rowmark24-May-10 15:09
rowmark24-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.