0

可能重复:
使用 tfs api 连接到 tfs 时身份验证失败

我面临一个奇怪的问题。我想以编程方式使用 tfs api 连接 tfs 服务器。即使在提供了正确的 authentcaion crdiatials 之后,它也会失败。但是如果我通过在浏览器中键入 tfs 服务器名称来手动完成它,它就会连接起来。

代码:

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

请建议。

4

2 回答 2

0

你可以用一种更简单的方式来做(假设你已经通过了身份验证):

var tfsCollection = new TfsTeamProjectCollection(new Uri("http://yourtfs:8080/tfs/"));
tfsCollection.Authenticate();
var workItemStore = new WorkItemStore(TfsCollection);
于 2012-12-13T13:41:31.247 回答
0

您可能希望使用此替代方法

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);
            }
        }
    }
}
于 2012-12-13T13:34:08.803 回答