How To: Listen for Team Foundation Server (TFS) Event Notifications using Windows Communication Foundation (WCF)

I feel that this post requires musical accompaniment. Internally at Readify we have been looking at ways that we can extend our Team Foundation Server environment. One of the key ways you can do this is write code that subcribes to and listens for event notifications so that when things like check-ins or builds occur, you can respond.

The process for implementing event listening services typically involves going and downloading Howard van Rooijen’s pre-baked TFS Notification Web Services template, implementing your specific logic and deploying them to a box.

One of the issues that I have with Howard’s templates is that they are implementing using the new web-site project type as opposed to the even newer (but more reliable) Web Application Project template types, but on top of that I just don’t like the hassle of having to deploy a web-site and much around with IIS configuration settings (even once) to get the listener working, and that is before we even get to dealing with state management and constantly cycling application pools.

Enter Windows Communication Foundation

If something bothers me I like to do something about it, and this IIS configuration dependency was definately bothering me so I decided that I would attempt to host an event subscriber notification service inside WCF as a bit of a demonstration (I’ll probably expand on this a little in my presentation at TechEd 2006 in Sydney).

I wanted the demonstration to do two things, firstly I wanted it to automatically subscribe itself to the TFS event notification services when it started up and clean itself up when it shuts down, but also the specific tweaks that are required to the service endpoint documentation in the Visual Studio 2005 SDK. You can download the demo code from here, but the real active ingredient is the implementation of the WCF service.

    Namespace = "")]
public interface INotificationService
        Action = "",
        ReplyAction = "*")]
    [XmlSerializerFormat(Style = OperationFormatStyle.Document)] /* Took me hours to figure this out! */
    void Notify(string eventXml, string tfsIdentityXml);

public class NotificationServiceImpl : INotificationService
    public void Notify(string eventXml, string tfsIdentityXml)

So why the musical accompanyment? Well, it took me hours to figure out the reason the Notify method was silently failing to be executed was because I hadn’t specified that I wanted it to use document style encoding for the operation – “we are the champions” is the tune I had playing in my head when I finally got it working and was running around the house cheering like a soccer player that had just won the World Cup!


7 thoughts on “How To: Listen for Team Foundation Server (TFS) Event Notifications using Windows Communication Foundation (WCF)

  1. Eddie de Bear

    lol, I love nothing better than solving a tricky problem and running around.. I normally run around shouting “I am a legend” or “I rock”.. The problem I found is that nobody else seems to share my joy…

  2. Michael Luke

    The real reason it was failing is because your ServiceContract doesn’t match the XML sent out by Team Foundation Server.

    Your contract should look like this:

    [ServiceContract(Namespace = “”)]

    public interface ICheckInEvent


    [OperationContract(Action = “”)]

    void Notify(string eventXml, string tfsIdentityXml, SubscriptionInfo SubscriptionInfo);


    Where SubscriptionInfo has a DataContract like this:


    public class SubscriptionInfo



    public string ID;


    public string Subscriber;


    public string Classification;


  3. Darren Brust

    Looks interesting, I’d like to check it out.
    Does the demo code for this still exist?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s