2012-02-06 74 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> 

希望這有助於!當我遇到同樣的錯誤時爲我工作。