Click here to Skip to main content
13,354,605 members (57,763 online)
Click here to Skip to main content
Add your own
alternative version

Stats

65.7K views
1.4K downloads
19 bookmarked
Posted 3 Nov 2007

Exchange 2007 Push Notifications Using WCF

, 3 Nov 2007
Rate this:
Please Sign up or sign in to vote.
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.

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=""           

  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)

Share

About the Author

Ahmed Sadek
Engineer Lost Particles Network
Egypt Egypt
No Biography provided

You may also be interested in...

Pro
Pro

Comments and Discussions

 
Questionit used to work years ago Pin
rosone2-Feb-12 5:58
memberrosone2-Feb-12 5:58 
QuestionWhat about Exchange 2010 version? Pin
JamesQ30-Sep-10 17:40
memberJamesQ30-Sep-10 17:40 
AnswerRe: What about Exchange 2010 version? Pin
thepsion12-Jan-11 23:16
memberthepsion12-Jan-11 23:16 
QuestionHow do I get the subject of the new email Pin
rowmark24-May-10 5:18
memberrowmark24-May-10 5:18 
QuestionHow to get mail item Pin
Shahzad.Aslam17-May-10 1:33
memberShahzad.Aslam17-May-10 1:33 
AnswerRe: How to get mail item Pin
rowmark24-May-10 16:07
memberrowmark24-May-10 16:07 
GeneralRe: How to get mail item Pin
Shahzad.Aslam24-May-10 20:11
memberShahzad.Aslam24-May-10 20:11 
GeneralRe: How to get mail item Pin
rowmark25-May-10 5:08
memberrowmark25-May-10 5:08 
GeneralRe: How to get mail item Pin
Max Mendel26-May-10 8:29
memberMax Mendel26-May-10 8:29 
GeneralRe: How to get mail item Pin
Shahzad.Aslam26-May-10 19:50
memberShahzad.Aslam26-May-10 19:50 
GeneralRe: How to get mail item Pin
rowmark3-Jun-10 6:58
memberrowmark3-Jun-10 6:58 
GeneralRe: How to get mail item Pin
rowmark3-Jun-10 6:50
memberrowmark3-Jun-10 6:50 
GeneralGetting error in opening host Pin
Shahzad.Aslam29-Apr-10 22:49
memberShahzad.Aslam29-Apr-10 22:49 
GeneralException While Subscribing to PushNotification Pin
rajendrakumar4u18-Apr-10 21:38
memberrajendrakumar4u18-Apr-10 21:38 
QuestionException on running the sample program Pin
brahan_k_v15-Sep-09 3:29
memberbrahan_k_v15-Sep-09 3:29 
AnswerRe: Exception on running the sample program Pin
gkriggs5-May-10 9:40
membergkriggs5-May-10 9:40 
GeneralNo source code Pin
bittondb4-May-09 10:03
memberbittondb4-May-09 10:03 
GeneralNot getting notification for subscribed events. Pin
vacmkrishh23-Oct-08 3:00
membervacmkrishh23-Oct-08 3:00 
QuestionWhy two projects? Pin
ReeY8-Aug-08 1:05
memberReeY8-Aug-08 1:05 
QuestionWCF not getting events for the subscripton Pin
Neil@iCope24-Mar-08 22:19
memberNeil@iCope24-Mar-08 22:19 
GeneralRe: WCF not getting events for the subscripton Pin
Ahmed Sadek25-Mar-08 14:54
memberAhmed Sadek25-Mar-08 14:54 
GeneralRe: WCF not getting events for the subscripton Pin
rowmark24-May-10 16:09
memberrowmark24-May-10 16: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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180111.1 | Last Updated 3 Nov 2007
Article Copyright 2007 by Ahmed Sadek
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid