2012-02-06 76 views
6

我试过两种方式连接到我们正在运行的TFS服务器的workitemstore。尝试A将连接到配置服务器并使用GetService<WorkItemStore>()方法。这总是返回null。如何成功连接到TFS 2010 workitem商店?

尝试B连接到TfsTeamProjectCollection,并使用GetService<WorkItemStore>()方法或将项目集合传递给WorkItemStore构造函数。在尝试B上,我收到一个异常,指出“错误HRESULT E_FAIL已从调用COM组件返回。”我能找到的唯一信息似乎表明有一些权限问题,但我已确认我是通过对整个项目集合的读取权限进行身份验证的,并且我通过VS 2011 dev预览进行了适当的连接和干预。

这里是我如何连接?

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; 
    } 

和这里的如何,我试图让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."); 
    } 

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

+0

附加信息:相同的代码在我们的域中使用Windows身份验证和模拟的计算机上正常工作。我想我不能从域外做到这一点?我可以从Visual Studio中,所以没有任何意义。也许如果我可以冒充域用户,即使我不在域上? – sonicblis 2012-02-07 00:23:57

回答

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); 
     } 
    } 
} 
+1

在控制台应用程序中工作(一旦我添加身份验证),在我的Web应用程序中不起作用。在我的问题中与尝试B相同的错误。 – sonicblis 2012-02-06 21:11:49

+0

对不起,它没有为你工作 – pantelif 2012-02-06 22:40:51

0

我相信this article也许能回答你的问题。它说,如果你在一个稍微不同的方式实例化WorkItemStore,你会得到一个不同的异常:

System.TypeInitializationException: The type initializer for ‘Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore’ threw an exception. —> System.IO.FileLoadException: Mixed mode assembly is built against version ‘v2.0.50727′ of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.

的修复是一个简单的web.config变化,加入以下内容:

<?xml version="1.0"?> 
<configuration> 
    <startup useLegacyV2RuntimeActivationPolicy="true"> 
     <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> 
    </startup> 
</configuration> 

希望这有助于!当我遇到同样的错误时为我工作。