Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does one successfully connect to the TFS 2010 workitem store?

I've tried two ways of connecting to the workitemstore for the TFS server we're running. Attempt A was to connect to the configuration server and use GetService<WorkItemStore>() method. This always returns null.

Attempt B was to connect to the TfsTeamProjectCollection and use the GetService<WorkItemStore>() method or pass the project collection into the WorkItemStore constructor. On attempt B, I get an exception stating "Error HRESULT E_FAIL has been returned from a call to a COM component." The only info I can find on that seems to indicate some permissions problem, but I've confirmed I'm authenticated as a user with read access to the whole project collection and I connect and meddle appropriately via VS 2011 dev preview.

Here's how I'm connecting...

    public TfsConfigurationServer GetConfigurationServer()
    {
        Uri tfsUri = new Uri(configs.TfsUri);
        TfsConfigurationServer server = TfsConfigurationServerFactory.GetConfigurationServer(tfsUri, credProvider);
        server.Authenticate();
        if (server.HasAuthenticated == false)
            throw new InvalidOperationException("You can't authenticate against the tfs instance.");
        return server;
    }

    public TfsTeamProjectCollection GetProjectCollectionInstance(string projectCollectionName)
    {
        Uri tfsUri = new Uri(configs.TfsUri + "/" + projectCollectionName);         
        TfsTeamProjectCollection collection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(tfsUri, credProvider);
        collection.Authenticate();
        if (collection.HasAuthenticated == false)
            throw new InvalidOperationException("You can't authenticate against the tfs instance.");
        return collection;
    }

and here's how I'm trying to get the WorkItemStore (silly code to illustrate the problem)...

    public WorkItemProvider()
    {
        if (workItems == null)
            workItems = ServerProvider.ServerInstance.GetService<WorkItemStore>();
        if (workItems == null)
            workItems = ServerProvider.ProjectCollectionInstance.GetService<WorkItemStore>();
        if (workItems == null)
            workItems = new WorkItemStore(ServerProvider.ProjectCollectionInstance);
        if (workItems == null)
            throw new NullReferenceException("Couldn't load work item store.");
    }

I'm not on the same domain as the server, but I'm authenticating as a domain user with an ICredentialsProvider and I've confirmed I'm authenticated as that user. Any pointers would be helpful.

like image 684
sonicblis Avatar asked Feb 06 '12 02:02

sonicblis


1 Answers

Check if this does what you need:

using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace GetsWorkItem
{
    class Program
    {
        static void Main()
        {
            TfsTeamProjectCollection teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://<TFS>:8080/tfs/<COLLECTION>"));
            WorkItemStore workItemStore= (WorkItemStore) teamProjectCollection.GetService(typeof (WorkItemStore));

            WorkItem workItem = workItemStore.GetWorkItem(1234);
        }
    }
}
like image 161
pantelif Avatar answered Sep 28 '22 00:09

pantelif