We are finally in the process of implementing Visual Studio TFS where I work. In our process exploration we decided we would need to write a webservice that TFS could notify whenever a workitem or other change happened.
TFS lets you setup alerts, in 2010 you can simply do this by going to the Team->Alerts Explorer window. You are greeted with an interface that lets you setup an alert type, conditions for the alert, and how you want the alert to happen. You can alert people via Plain Text or HTML email OR you can also alert a webservice/wcf via SOAP. Basically when the conditional is met it makes a SOAP call to a webservice you setup.
There were no real "starter projects" that I could find that were for building it using WCF in VIsual Studio 2010/.net framework 4.0. Everything on the web was a bit outdated. Needless to say when I created the service and setup the alert to call it nothing happened. The first step was figuring out why the failure happened and to do this you need to setup the TFS server to log what happens when it tries to make the alert. This is done by editing the TFSJobAgent.exe.config file located on the TFS application server in the C:\Program Files\Microsoft Team Foundation Server 2010\Application Tier\TFSJobAgent folder. You need to edit the system.diagnostics section, here's how mine looks:
<trace autoflush="false" indentsize="4">
<!--To enable tracing to file, simply uncomment listeners section and set trace switch(es) below.
Directory specified for TextWriterTraceListener output must exist, and job agent service account must have write permissions. -->
<remove name="Default" />
<!-- Trace Switches
Each of the trace switches should be set to a value between 0 and 4, inclusive.
0: No trace output
1-4: Increasing levels of trace output; see Systems.Diagnostics.TraceLevel-->
<add name="API" value="0" />
<add name="Authentication" value="0" />
<add name="Authorization" value="0" />
<add name="Database" value="0" />
<add name="General" value="3" />
<add name="traceLevel" value="1" />
This logs things, including the status of alert failures to c:\windows\temp\jobagent.log (you can change this of course). Once you do this you need to restart the Visual Studio Team Foundation Background Job Agent" service.
Checking the logs I saw that the following error message ocurring (just posting relevant section): HTTP code 415: Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'
After much googling I discovered that this is because TFS 2010 is using SOAP 1.2 and needs wsHttpBinding setup on the service application. Unfortunately this took me forever to figuer out how to get it working. I had to modify my services web.config but kept getting errors because I wasn't specifying the full name <namespace.interface/class> in my web.config. With no starter/sample project to work with I was flying pretty blind and the error messages were not very intuitive. After much trial and error I figured out the proper web.config settings and all was working!
Attached is a great sample/starter project for creating your TFS2010 notification WCF services in Visual Studio 2010/.net 4.0. My sample is posted in VB but it is easy to convert to C#. Hopefully this helps others avoid the confusion, frustrations and problems I had. It would be nice if MS would've shipped a starter template for creating this but they did not.
Also note that notifications by default are processed in batch every 2 minutes in TFS 2010. You can set this to a shorter value by following this article (just paste the commands into powershell): http://blogs.msdn.com/b/chrisid/archive/2010/03/05/faster-delivery-of-notifications.aspx.
(Updated 6/18/2010) I just updated the sample project. It now contains code to nicely parse out the eventXML into an object! I used Linq for the XML parsing. This is now a great starter project that you can use not only to get your service running but also get a defined "ChangedWorkItem" object to work with.