如何成功连接到TFS 2010工作项目商店?

son*_*lis 6 tfs tfs2010 tfs-workitem

我已经尝试了两种方法连接到我们正在运行的TFS服务器的workitemstore.尝试A是连接到配置服务器和使用GetService<WorkItemStore>()方法.这总是返回null.

尝试B是连接到TfsTeamProjectCollection并使用该GetService<WorkItemStore>()方法或将项目集合传递给WorkItemStore构造函数.在尝试B时,我得到一个异常,说明"从调用COM组件返回错误HRESULT E_FAIL".我可以在其上找到的唯一信息似乎表明存在一些权限问题,但我已经确认我已经通过身份验证作为具有对整个项目集合的读取权限的用户,并且我通过VS 2011开发预览进行了适当的连接和插入.

这是我如何连接......

    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;
    }
Run Code Online (Sandbox Code Playgroud)

这就是我如何尝试获取WorkItemStore(愚蠢的代码来说明问题)...

    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.");
    }
Run Code Online (Sandbox Code Playgroud)

我与服务器不在同一个域中,但是我作为具有ICredentialsProvider的域用户进行身份验证,并且我已经确认我已经过该用户的身份验证.任何指针都会有所帮助.

pan*_*lif 2

检查这是否满足您的需要:

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);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)