Connecting to TFS
I managed to make a short program which connects to the TFS Server and extracts information from it. The program is written in C#, and is not really hard to make. I'm not sure though if that's the right way to go. I know that I can implement some C# code in my webservice, but it's still not clear to me if I should connect to TFS this way or another.
Anyway, I do it like this, in a simple C# console application (yes, it is from an article at MSDN - I just don't remember the source right now):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
namespace MyFirstApplicationForTFS
{
class Program
{
static void Main(string[] args)
{
// Let the user choose a TFS Server
Console.Write("Please enter a valid TFS Server or URI: ");
String tfsServer = Console.ReadLine();
tfsServer = tfsServer.Trim();
// Connect to the TeamFoundation Server
Console.WriteLine();
Console.Write("Connecting to Team Foundation Server {0}...", tfsServer);
TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(tfsServer);
// Example: Connect to the WorkItemStore
Console.WriteLine();
Console.Write("Reading from the Work Item Store...");
WorkItemStore workItemStore = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));
// Example: Display the details about the teamFoundationServer
Console.WriteLine("\n");
Console.WriteLine("Team Foundation Server Details");
Console.WriteLine("Server name: " + tfs.Name);
Console.WriteLine("Uri: " + tfs.Uri);
Console.WriteLine("AuthenticatedDisplayName: " + tfs.AuthenticatedUserDisplayName);
Console.WriteLine("AuthenticatedUserName: " + tfs.AuthenticatedUserName);
Console.WriteLine("workItemStore:");
// Example: List the projects in the WorkItemStore.
Console.WriteLine(" Projects.Count: " + workItemStore.Projects.Count);
foreach (Project pr in workItemStore.Projects)
{
Console.WriteLine(" " + pr.Name);
}
Console.WriteLine("\n\nDONE!");
}
}
}
It works fine, I've tried it on the TFS VPC. But as I said, I'm not sure that I'm on the right track here. Perhaps webservices that are to be a part of TFS should communicate in some other way with the server. I'll have to study some more. Please do give me some feedback on my thoughts!