如何使用来自 .Net Windows 服务的新基本身份验证对 Visual Studio Team Services 进行身份验证? [英] How to authenticate to Visual Studio Team Services with the new basic authentication from a .Net Windows Service?

查看:16
本文介绍了如何使用来自 .Net Windows 服务的新基本身份验证对 Visual Studio Team Services 进行身份验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试访问 https://visualstudio.com(以前称为 https://tfs.visualstudio.com, http://www.tfspreview.com) 来自我在 .NET 上编写的 Windows 服务.

I am trying to access https://visualstudio.com (formerly known as https://tfs.visualstudio.com, 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.

我发现了很多指向博客文章的链接 Team Foundation服务更新 - 8 月 27 日,但它使用 Team Explorer Everywhere 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?

顺便说一下,我已经连续使用服务帐号登录了.这个答案非常有用.

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

推荐答案

首先,您至少需要有 Visual Studio 2012 Update 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.

这是执行此操作的代码,来自 Buck 的博客文章如何连接到 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);
        }
    }
}

这篇关于如何使用来自 .Net Windows 服务的新基本身份验证对 Visual Studio Team Services 进行身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆