如何进行身份验证到Team Foundation服务,从.NET Windows服务的新的基本身份验证?

如何进行身份验证到Team Foundation服务,从.NET Windows服务的新的基本身份验证?

问题描述:

我想访问 https://tfs.visualstudio.com (原名的 HTTP://www.tfs$p$pview.com )从我的Windows服务写在.NET

I am trying to access https://tfs.visualstudio.com (formerly known as http://www.tfspreview.com) from my Windows Service written on .NET.

我想用新的基本身份验证,但我无法找到一个方法来做到这一点。

I want to use the new basic authentication but I couldn't find a way to do it.

我发现很多链接的博客文章团队基础服务更新 - 8月27日,但它使用的是团队资源管理器无处不在的Java客户端TFS

I found a lot of links to the blog post Team Foundation Service updates - Aug 27 but it is using the Team Explorer Everywhere Java client for TFS.

有TFS的.NET对象模型的新版本,以支持基本的认证?

Is there a new version of the TFS .NET Object Model to support the basic authentication?

顺便说一句,我先后登录的服务帐户。 This回答是非常有用的。

By the way I've successively logged in with the service account. This answer was very useful.

首先,你需要有至少的的Visual Studio 2012更新1 安装在您的计算机上。它包括一个更新的 Microsoft.TeamFoundation.Client.dll 装配与 BasicAuthCredential 类。

First of all, you need to have at least Visual Studio 2012 Update 1 installed on your machine. It includes an updated Microsoft.TeamFoundation.Client.dll assembly with the BasicAuthCredential class.

这里的code做到这一点,从Buck's博客文章如何连接到Team Foundation服务。

Here's the code to do it, from Buck's blog post How to connect to Team Foundation Service.

using System;
using System.Net;
using Microsoft.TeamFoundation.Client;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            NetworkCredential netCred = new NetworkCredential(
                "yourbasicauthusername@live.com",
                "yourbasicauthpassword");
            BasicAuthCredential basicCred = new BasicAuthCredential(netCred);
            TfsClientCredentials tfsCred = new TfsClientCredentials(basicCred);
            tfsCred.AllowInteractive = false;

            TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(
                new Uri("https://YourAccountName.visualstudio.com/DefaultCollection"),
                tfsCred);

            tpc.Authenticate();

            Console.WriteLine(tpc.InstanceId);
        }
    }
}