views:

169

answers:

2

How do I get list of projects from TFS server using webservice?

Is documentation available for the TFS Webservices?

+1  A: 

Your best bet is to use the TFS DLLs and that API, which is at http://msdn.microsoft.com/en-us/library/bb130146(VS.80).aspx and http://msdn.microsoft.com/en-us/library/bb130334(v=VS.80).aspx . From what I understand, hitting the webservice directly is frowned upon.

To get a list of projects, I think there's multiple ways to do this. I posted code I used: use the GetServer method to get a project collection, then list through the ListProjects() method. I needed to do this because I needed to get the areas and iterations as well. This requires the Microsoft.TeamFoundation.Client namespace.

var tfs = TeamFoundationServerFactory.GetServer(Constants.TEAMFOUNDSERVER);
var projectCollection  = (ICommonStructureService)tfs.GetService(typeof(ICommonStructureService));
foreach (var projectInfo in projectCollection.ListProjects()) 
{
     //do stuff here
}
bryanjonker
Thanks, I know it is good to use TFS DLLs. But I'm developing on Ubuntu, so I guess I don't have any better option to communicate TFS... If there is one please let me know
Prashant
I agree with Robaticus -- write your own webservice layer in .NET and execute this. Otherwise, when Microsoft changes their webservice layer, you'll need to do a lot of rework. Or, go with Mono? I believe the DLLs are managed code.
bryanjonker
+1  A: 

I concur with bryanjonker as well. Don't call the webservice directly, that's really reserved for internal use. Create your own access layer and call the API.

You can also use the object model to get access to the ICommonStructureService. I've recently started using this, and find it to be cleaner. The code below does the same as bryanjonker's example:

    var tfs = TeamFoundationServerFactory.GetServer(serverUri);

    var projectCollection = tfs.GetService<ICommonStructureService>();

    foreach (var projectInfo in projectCollection.ListProjects())
    {
        listBox1.Items.Add(projectInfo.Name);
    }
Robaticus
Thanks, I know it is good to use TFS DLLs. But I'm developing on Ubuntu, so I guess I don't have any better option to communicate TFS... If there is one please let me know
Prashant
Can you create a web service layer for yourself that sits on the TFS server?
Robaticus