繁体   English   中英

通过HTTP代理从C#连接到TFS

[英]Connect to TFS from C# via HTTP proxy

我正在为TFS 2012编写一个小型C#报告应用程序。

TFS服务器是远程的,只能通过网络中的HTTP代理服务器进行访问,因为防火墙会阻止直接访问。

代理是在Internet Explorer中配置的,因此我可以在IE中打开TFS URL,并且在使用TFS时Visual Studio会自动使用它。

问题是我的应用程序将忽略IE代理设置,并尝试直接连接到TFS服务器(我在Wireshark中看到了这一点),因此由于防火墙而导致超时后失败。

这是我使用的代码:

Uri TfsCollectionURL = new Uri("...");
NetworkCredential credential = new System.Net.NetworkCredential(Username, Password, Domain);
TfsTeamProjectCollection collection = new TfsTeamProjectCollection(TfsCollectionURL, credential);
collection.EnsureAuthenticated();
ICommonStructureService projectService = collection.GetService<ICommonStructureService>();
foreach (ProjectInfo project in projectService.ListProjects())
{
    ...
}

申请失败。 确保为AuthenticAuthenticated (),但例外:

TF400324:服务器无法使用Team Foundation服务...

连接尝试失败是因为一段时间后连接方未正确响应,或者由于连接的主机未能响应而导致建立连接失败...

它确实可以在允许直接访问TFS服务器的另一个子网中工作。

题:

如何在C#应用程序中使用HTTP代理连接到TFS?

尝试添加App.config文件以使用以下代码设置默认代理:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.net>
        <defaultProxy enabled="true" useDefaultCredentials="true"></defaultProxy>
    </system.net>
</configuration>

您可以直接设置凭据以通过代理:

WebProxy p = new WebProxy("proxyserver.domain.com:8080", true);
p.Credentials = new NetworkCredential("domain\\user", "password");
WebRequest.DefaultWebProxy = p;

在我的方案中,我们有一个用于开发的子网,并且不允许这些帐户/计算机访问Internet。 因此,我们需要输入上级域代理和这些域凭据才能访问Internet。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM