使用tfs api连接到tfs时身份验证失败

时间:2012-12-13 06:20:44

标签: c# asp.net tfs tfs2010

  

可能重复:
  authentication failed while connecting to tfs using tfs api

我面临一个奇怪的问题。我想使用tfs api programmitcally连接tfs服务器。 即使在提供了正确的认证信用之后,它也是失败的。但是如果我通过在浏览器中输入tfs服务器名称手动完成它就已经连接了。

代码:

TeamFoundationServer tfs = 
      new TeamFoundationServer(new Uri("http://xx.xx.xx.xx:8080/tfs"), 
                        new NetworkCredential(@"user", "pass", "domain"));
tfs.EnsureAuthenticated()

请建议。

2 个答案:

答案 0 :(得分:0)

您可能想要使用此alternative

using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Framework.Client;
using Microsoft.TeamFoundation.Framework.Common;
using System;
using System.Collections.ObjectModel;

class Program
{
    static void Main()
    {
        var tfsUri = new Uri("http://xx.xx.xx.xx:8080/tfs");

        TfsConfigurationServer configurationServer =
                TfsConfigurationServerFactory.GetConfigurationServer(tfsUri);

        // Get the catalog of team project collections
        ReadOnlyCollection<CatalogNode> collectionNodes = configurationServer.CatalogNode.QueryChildren(
            new[] { CatalogResourceTypes.ProjectCollection },
            false, CatalogQueryOptions.None);

        // List the team project collections
        foreach (CatalogNode collectionNode in collectionNodes)
        {
            // Use the InstanceId property to get the team project collection
            Guid collectionId = new Guid(collectionNode.Resource.Properties["InstanceId"]);
            TfsTeamProjectCollection teamProjectCollection = configurationServer.GetTeamProjectCollection(collectionId);

            // Print the name of the team project collection
            Console.WriteLine("Collection: " + teamProjectCollection.Name);

            // Get a catalog of team projects for the collection
            ReadOnlyCollection<CatalogNode> projectNodes = collectionNode.QueryChildren(
                new[] { CatalogResourceTypes.TeamProject },
                false, CatalogQueryOptions.None);

            // List the team projects in the collection
            foreach (CatalogNode projectNode in projectNodes)
            {
                Console.WriteLine(" Team Project: " + projectNode.Resource.DisplayName);
            }
        }
    }
}

答案 1 :(得分:0)

你可以a simpler way(假设你已通过身份验证):

var tfsCollection = new TfsTeamProjectCollection(new Uri("http://yourtfs:8080/tfs/"));
tfsCollection.Authenticate();
var workItemStore = new WorkItemStore(TfsCollection);