无法从 C# 连接到 Azure DevOps Repo
Unable to connect to Azure DevOps Repo from C#
我有一个网络 api,它连接到 azure devops 存储库并检索一些文件以执行一些操作。问题是,我无法从网络服务进行连接。我收到错误 "SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond"。但是,相同的代码 运行 在控制台应用程序中完全没问题。
VssConnection connection = new VssConnection(new Uri("https://dev.azure.com/org"), new VssBasicCredential(string.Empty, "psa"));
TfvcHttpClient tfvcClient = connection.GetClient<TfvcHttpClient>(); //error here
string projectName = "Project";
string scopePath = $"$/{projectName}/";
List<TfvcItem> items = tfvcClient.GetItemsAsync(scopePath: scopePath, recursionLevel: VersionControlRecursionType.OneLevel).Result;
Console.WriteLine("Connection Established");
奇怪的是,一旦我通过控制台应用程序建立连接,如果我通过 Web 服务 运行 相同的代码,它就可以工作。我关闭了防火墙并进行了检查,但没有任何效果。卡了这么久!
努力让它工作几天后,在 web.config 中启用默认代理后它工作正常:
<system.net>
<defaultProxy enabled="true" useDefaultCredentials="true">
<proxy usesystemdefault="True" />
</defaultProxy>
我有一个网络 api,它连接到 azure devops 存储库并检索一些文件以执行一些操作。问题是,我无法从网络服务进行连接。我收到错误 "SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond"。但是,相同的代码 运行 在控制台应用程序中完全没问题。
VssConnection connection = new VssConnection(new Uri("https://dev.azure.com/org"), new VssBasicCredential(string.Empty, "psa"));
TfvcHttpClient tfvcClient = connection.GetClient<TfvcHttpClient>(); //error here
string projectName = "Project";
string scopePath = $"$/{projectName}/";
List<TfvcItem> items = tfvcClient.GetItemsAsync(scopePath: scopePath, recursionLevel: VersionControlRecursionType.OneLevel).Result;
Console.WriteLine("Connection Established");
奇怪的是,一旦我通过控制台应用程序建立连接,如果我通过 Web 服务 运行 相同的代码,它就可以工作。我关闭了防火墙并进行了检查,但没有任何效果。卡了这么久!
努力让它工作几天后,在 web.config 中启用默认代理后它工作正常:
<system.net>
<defaultProxy enabled="true" useDefaultCredentials="true">
<proxy usesystemdefault="True" />
</defaultProxy>