How to: Initialize a WorkItem instance for the changed work item in WorkItemChangedEvent handler

Recently I’ve been asked about several questions that need to initialize a WorkItem instance in the web service handler for WorkItemChangedEvent. So I paste a sample code here to ease the future references.

One thing to note is that in order to query work items, the identity for the app pool that hosts the web service in IIS must has property permission granted. In TFS 2005 and 2008, work item permissions are based on area and iteration. See Team Foundation Server Permissions for more information.

using System;
using System.Diagnostics;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace EventHandler
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class WorkItemChangedEventHandler : System.Web.Services.WebService
{

[SoapDocumentMethod(
Action = "http://schemas.microsoft.com/TeamFoundation/2005/06/Services/Notification/03/Notify",
RequestNamespace = "http://schemas.microsoft.com/TeamFoundation/2005/06/Services/Notification/03")]
[WebMethod]
public void Notify(string eventXml)
{
try
{
string tfsUrl = "http://TFS_AT:8080";
TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(tfsUrl);

var workItemId = GetWorkItemID(eventXml);

var wis = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));
var wi = wis.GetWorkItem(workItemId);


}
catch (Exception e)
{
var eventSource = "My WorkItemChangedEvent Handler";
var logName = "Application";
var machineName = "."; //local computer.

if (!EventLog.SourceExists(eventSource, machineName))
{
var eventObj = new EventSourceCreationData(eventSource, logName);
EventLog.CreateEventSource(eventObj);
}

var eventLog = new EventLog(logName, machineName, eventSource);
eventLog.WriteEntry(e.Message);
}
}

private int GetWorkItemID(string eventXml)
{
var doc = new XmlDocument();
doc.LoadXml(eventXml);
var path = "/WorkItemChangedEvent/CoreFields/IntegerFields/Field[ReferenceName='System.Id']/NewValue";
var node = doc.SelectSingleNode(path);

var id = int.Parse(node.InnerText);
return id;
}

}
}

6 comments:

guangming April 25, 2010 at 7:12 PM

Discount Handbags On Sale-Beautycasa Online : Official online destination for all things Louis Vuitton Handbags and purses including Luxury Handbags trends, designer reviews, handbag deals, and more.Hot sale Cheap cell phonesand cell phone china on our site! Fashion look and powerful functions for these mobile phones even discount cell phones! Wholesale HiPhone, 3G cell phones, PDA/Smart Phone now.China Cell PhonesDon't miss these cellphone!toy wholesale

wholesale clothing February 9, 2011 at 12:33 AM

I totally agree with you!Keep on posting!!! 2945abc45 0209

Stacey August 11, 2011 at 8:00 AM
This comment has been removed by the author.
Adobe Acrobat 9 Download June 16, 2013 at 7:33 AM

Acrobat 9 Pro Extended is the complete PDF solution for business and technical professionals.
Acrobat 9 Pro helps business and creative professionals communicate and collaborate more effectively and securely with virtually anyone, anywhere. Unify a wide range of content in a single organized PDF Portfolio. Collaborate through electronic document reviews. Create and manage dynamic forms. And help protect sensitive information.
Microsoft Project 2010 Download delivers innovative features across the entire family of products: Microsoft Project Standard 2010 Download and Microsoft Project Professional 2010 Download for occasional and professional project managers, and Project Professional 2010, combined with Microsoft Project Server 2010, for the power and depth to meet the needs of larger organisations.

Situs Poker Idn Play October 30, 2019 at 10:39 PM

Artikel yang sangat bagus menarik dan bermanfaat

Bergabunglah dan rasakan sensasi bermain Situs Poker, Domino99, Pokerqq, QQ Online, Domino Qiu, Qiu Qiu Online, Poker Qiu Qiu yang memberikan kemenangan besar hanya di

http://Maxbetqq.net/ Agen Poker IDN terpercaya yang memberikan kemananga besar jackpot besar bersama Situs Poker Idn Play.

Dengan didukung server yang berkulitas dan permainan yang sangat fair 100% Player vs Player dan tidak ada campur tangan ROBOT di dalam Situs Poker Online Terpercaya

MaxbetQQ.

Promo HOT Di Poker Online Terpercaya Maxbetqq :
– Bonus Bulanan Megajackpot
– Bonus New Member 20% (Minimal Deposit Rp25.000 | Maksimal Bonus Rp.50.000)
– Bonus Rollingan 0,5%
– Bonus Deposit Rp. 5000 Setiap Hari
– Bonus Refferal 10% Up To 60%

7 Games Dalam 1 User ID :

✔️ Texas Poker
✔️ Domino QQ
✔️ Capsa Susun
✔️ Bandar Ceme
✔️ Ceme Keliling
✔️ Super Ten
✔️ Pot OMAHA

Info Maxbetqq Anda Bisa Langsung Menghubungi Lewat :

Livechat : http://Maxbetqq.net/
Whatsapp : +66613295868
WeChat : MaxbetQQ
Line : MaxbetQQ


QQ NET
QQ.NET
QQ PAGCOR
ONLINE QQ
DAFTAR QQ
QQ ONLEN
POKERQQ
POKERQQIDN
QQ ONLINE
DOMINO QIU
POKER ONLINE
MAXBETQQ.NET
SITUS POKER
AGEN POKERQQ
AGEN DOMINO99
POKER QIU QIU
QIU QIU ONLINE
Idn Poker
Idn Poker Apk
Agen Poker Idn
Idn Poker Play
Poker Idn Play
Situs Judi Poker
Idn Poker Terbaru
Game Poker Online
Situs Judi Poker Terbaik
Situs Poker Idn Play
Agen Poker Idn Terpercaya
Agen Poker Idn Terbaik
Situs Poker Idn Uang Asli
Bandar Poker Idn Indonesia
Situs Judi Poker Terpercaya
AGEN POKER UANG ASLI
AGEN POKER TERPERCAYA