Click here to Skip to main content
15,905,419 members
Articles / DevOps / Testing

Team Foundation Server (TFS) API Wrapper

Rate me:
Please Sign up or sign in to vote.
4.62/5 (7 votes)
23 Jun 2010CPOL3 min read 71K   2.3K   21   9
A simple wrapper that encapsulates exposed functions of the Microsoft Team Foundation Server (TFS) client API



In this article, I want to introduce a small .NET wrapper class library to you that encapsulates several exposed classed of the client API of Microsoft Team Foundation Server (TFS).

Why Develop a Wrapper Around a Wrapper?

Maybe you ask yourself why I am developing a wrapper library around the already wrapped SOAP interface of TFS.

The original requirement for connecting to and communicating with a TFS was when I developed the TFS integration of our Test Management Environment Zeta Test. The application enables testers and test managers to create and manage test cases and manage black-box tests, white-box tests and regression tests. A customer brought up the need for connecting their existing TFS data base to Zeta Test.

While planning the developed enhancement, I wanted to be 100% sure that other clients that have no TFS Explorer (the client runtime for connecting to TFS) installed are still able to work with our application. So no dependencies between the TFS client libraries and our main applications should exist.

Therefore I created the wrapper, which is the only assembly that references the TFC client API libraries.

Features of the Wrapper

The API wrapper is a small wrapper around several functions of the TFS Client API functions that deal with the work item tracking architecture.

The following main classes are provided:

  • FieldController
  • FieldDefinitionController
  • ProjectController
  • ServerConfiguration
  • ServerController
  • StoredQueryController
  • TfsAllowedValuesCollection
  • TfsAttachment
  • TfsAttachmentCollection
  • TfsField
  • TfsFieldCollection
  • TfsFieldDefinition
  • TfsFieldDefinitionCollection
  • TfsFieldFilter
  • TfsFieldFilterList
  • TfsLink
  • TfsLinkCollection
  • TfsProject
  • TfsProjectCollection
  • TfsRegisteredLinkType
  • TfsRegisteredLinkTypeCollection
  • TfsRevision
  • TfsRevisionCollection
  • TfsServer
  • TfsStoredQuery
  • TfsStoredQueryCollection
  • TfsTeamFoundationServer
  • TfsWorkItem
  • TfsWorkItemCollection
  • TfsWorkItemStore
  • TfsWorkItemType
  • TfsWorkItemTypeCollection
  • WorkItemController
  • WorkItemTypeController

These classes can be used to communicate with the Microsoft TFS. The screenshot at the top of the articles provides an idea of what I used it for. If you are interested, you can see the whole screenshot gallery over at Picasa.

Example Usage of the Classes

An example project is included in the download at the top of the article. Following are some typical usage scenarios.

var config = new ServerConfiguration
    ServerUrl = @"http://ukeim-js6hkkfzx:8080/"

The code above creates a configuration class. Usually, this is your first step when connecting. Specify all the settings that require you to connect. You can even specify impersonation to connect in a different user context (usually with higher privileges).

Next, you would create a class to connect to the server and then a class to connect to a certain project:

var serverController = new ServerController(config);

var projectController = 
    new ProjectController(

The example above creates a controller to connect to the server. By using this controller class, you could enumerate all projects (via the GetAllProjects() method).

With the project controller class, you could e.g. query for one or multiple work items that match a certain criteria:

var wis1 = projectController.GetWorkItemsByTitle(@"Set up");

foreach (var workItem in wis1)
    Console.WriteLine(@" " + workItem.Title)

You could also query for a certain field definition like the following:

var fd1 = projectController.Project.Store.GetFieldDefinition(-3);
var fd2 = projectController.Project.Store.GetFieldDefinition(10004);
var fd3 = projectController.Project.Store.GetFieldDefinition("ID");
var fd4 = projectController.Project.Store.GetFieldDefinition("Issue");

Please see the source files of the test project and the library itself for further examples.

What I Learned

Having no experience with TFS before starting this project, I really loved how easy it was to work with the TFS Client API. The structure is really well documented and easy to understand.

In fact, the hardest part by far was to set up TFS itself. I ended with a working VMware machine that I hopefully will never ever have to configure again.


In this article, I introduced a library that wraps several Microsoft Team Foundation Server functions. I've also shown you a brief overview of how to use the library.

If you have any questions, suggestions or want to report issues, I would love to hear from you! Please use the discussion section at the bottom of this article.


  • 2010-06-23 - First release to


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Chief Technology Officer Zeta Software GmbH
Germany Germany
Uwe does programming since 1989 with experiences in Assembler, C++, MFC and lots of web- and database stuff and now uses ASP.NET and C# extensively, too. He has also teached programming to students at the local university.

➡️ Give me a tip 🙂

In his free time, he does climbing, running and mountain biking. In 2012 he became a father of a cute boy and in 2014 of an awesome girl.

Some cool, free software from us:

Windows 10 Ereignisanzeige  
German Developer Community  
Free Test Management Software - Intuitive, competitive, Test Plans.  
Homepage erstellen - Intuitive, very easy to use.  

Comments and Discussions

QuestionTFS API connection from swift/obj-C Pin
Member 1146964931-Aug-15 6:05
Member 1146964931-Aug-15 6:05 
QuestionSolution Throwing error Pin
Member 1106091215-Jun-15 0:13
Member 1106091215-Jun-15 0:13 
QuestionClient api help Pin
aiswaryarajendran3-Dec-14 19:18
aiswaryarajendran3-Dec-14 19:18 
Questionnull object of WorkItemStore _store Pin
CodeBlack21-Jan-13 20:13
professionalCodeBlack21-Jan-13 20:13 
QuestionHow to connect to TFS site from C# application? Pin
Pranil S Yambal31-Oct-12 5:15
Pranil S Yambal31-Oct-12 5:15 
GeneralTeamFoundation version Pin
super_freax16-Dec-10 22:18
super_freax16-Dec-10 22:18 
GeneralRe: TeamFoundation version Pin
makarand keer10-Nov-11 11:06
makarand keer10-Nov-11 11:06 
GeneralTFS2010 Pin
rodionmarx17-Sep-10 4:13
rodionmarx17-Sep-10 4:13 
GeneralRe: TFS2010 Pin
Uwe Keim17-Sep-10 4:14
sitebuilderUwe Keim17-Sep-10 4:14 

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.