How TO Subscribe TFS Event Using Web Service

Team Foundation Eventing Service delivers notification of events by e-mail or through Web services. If we subscribe TFS Event using Web Service, we can do much more then E-mail.

1 Create a Asp.NET Web Service Project

The default name of the Web Method which is to handle the event is “Notify”, so there is only one method that could used for event handling in a web service class.

In this project, we need add “Microsoft.TeamFoundation” and “Microsoft.TeamFoundation.Server” to references. Following is the same code of a web service.

using System.Web.Services;
using System.Web.Services.Protocols;
using Microsoft.TeamFoundation.Server;

namespace EventService
{
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    public class EventProcess : 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, string tfsIdentityXml, SubscriptionInfo SubscriptionInfo)
        {
            //To do your own code with eventXml
        }
    }
}

 

2 Create a Application in IIS for Web Service

Commonly we create a application which include our web services under the web site “Team Foundation Server”(8080) directly, and with the same Application Pool as TFS.

image

 

3 Subscribe TFS Event

Team Foundation Server Event Subscription Tool is a  GUI tool for subscribing to events on a Team Foundation Server.

 

image

4 The eventXml is like

<?xml version="1.0" encoding="utf-16"?>
<WorkItemChangedEvent xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <PortfolioProject>TestTFS</PortfolioProject>
  <ProjectNodeId>193533da-2679-4b4f-9139-968994b181c4</ProjectNodeId>
  <AreaPath>\TestTFS</AreaPath>
  <Title>TestTFS Work Item Changed: My Bug 303 - wrwerw</Title>
  <WorkItemTitle>wrwerw</WorkItemTitle>
  <Subscriber>****************</Subscriber>
  <ChangerSid>S-1-5-21-4238651936-3394031355-3752556331-1021</ChangerSid>
  <DisplayUrl>http://tfs-sql2008sp1:8080/WorkItemTracking/WorkItem.aspx?artifactMoniker=303</DisplayUrl>
  <TimeZone>东部澳大利亚标准时间</TimeZone>
  <TimeZoneOffset>+10:00:00</TimeZoneOffset>
  <ChangeType>Change</ChangeType>
  <CoreFields>
    <IntegerFields>
      <Field>
        <Name>ID</Name>
        <ReferenceName>System.Id</ReferenceName>
        <OldValue>303</OldValue>
        <NewValue>303</NewValue>
      </Field>
      <Field>
        <Name>Rev</Name>
        <ReferenceName>System.Rev</ReferenceName>
        <OldValue>1</OldValue>
        <NewValue>2</NewValue>
      </Field>
      <Field>
        <Name>AreaID</Name>
        <ReferenceName>System.AreaId</ReferenceName>
        <OldValue>1</OldValue>
        <NewValue>1</NewValue>
      </Field>
    </IntegerFields>
    <StringFields>
      <Field>
        <Name>Work Item Type</Name>
        <ReferenceName>System.WorkItemType</ReferenceName>
        <OldValue>My Bug</OldValue>
        <NewValue>My Bug</NewValue>
      </Field>
      <Field>
        <Name>Title</Name>
        <ReferenceName>System.Title</ReferenceName>
        <OldValue>wrwerw</OldValue>
        <NewValue>wrwerw</NewValue>
      </Field>
      <Field>
        <Name>Area Path</Name>
        <ReferenceName>System.AreaPath</ReferenceName>
        <OldValue>\TestTFS</OldValue>
        <NewValue>\TestTFS</NewValue>
      </Field>
      <Field>
        <Name>State</Name>
        <ReferenceName>System.State</ReferenceName>
        <OldValue>Active</OldValue>
        <NewValue>Active</NewValue>
      </Field>
      <Field>
        <Name>Reason</Name>
        <ReferenceName>System.Reason</ReferenceName>
        <OldValue>New</OldValue>
        <NewValue>New</NewValue>
      </Field>
      <Field>
        <Name>Assigned To</Name>
        <ReferenceName>System.AssignedTo</ReferenceName>
        <OldValue>*****************</OldValue>
        <NewValue>*****************</NewValue>
      </Field>
      <Field>
        <Name>Changed By</Name>
        <ReferenceName>System.ChangedBy</ReferenceName>
        <OldValue>*****************</OldValue>
        <NewValue>*****************</NewValue>
      </Field>
      <Field>
        <Name>Created By</Name>
        <ReferenceName>System.CreatedBy</ReferenceName>
        <OldValue>**************</OldValue>
        <NewValue>**************</NewValue>
      </Field>
      <Field>
        <Name>Changed Date</Name>
        <ReferenceName>System.ChangedDate</ReferenceName>
        <OldValue>2009/11/26 12:34:49</OldValue>
        <NewValue>2009/11/26 12:38:58</NewValue>
      </Field>
      <Field>
        <Name>Created Date</Name>
        <ReferenceName>System.CreatedDate</ReferenceName>
        <OldValue>2009/11/26 12:34:49</OldValue>
        <NewValue>2009/11/26 12:34:49</NewValue>
      </Field>
      <Field>
        <Name>Authorized As</Name>
        <ReferenceName>System.AuthorizedAs</ReferenceName>
        <OldValue>********************</OldValue>
        <NewValue>********************</NewValue>
      </Field>
      <Field>
        <Name>Iteration Path</Name>
        <ReferenceName>System.IterationPath</ReferenceName>
        <OldValue>\TestTFS</OldValue>
        <NewValue>\TestTFS</NewValue>
      </Field>
    </StringFields>
  </CoreFields>
  <TextFields>
    <TextField>
      <Name>Workaround</Name>
      <ReferenceName>Demo.Workaround</ReferenceName>
      <Value>ytryrty</Value>
    </TextField>
  </TextFields>
  <ChangedFields>
    <IntegerFields />
    <StringFields>
      <Field>
        <Name>WorkaroundStatus</Name>
        <ReferenceName>Demo.WorkaroundStatus</ReferenceName>
        <OldValue />
        <NewValue>Exists</NewValue>
      </Field>
      <Field>
        <Name>TransitionBriefTemp</Name>
        <ReferenceName>Demo.TransitionBriefTemp</ReferenceName>
        <OldValue>1</OldValue>
      </Field>
    </StringFields>
  </ChangedFields>
</WorkItemChangedEvent>

posted on 2009-11-26 10:03  Ruiz  阅读(3661)  评论(0编辑  收藏  举报

导航