簡體   English   中英

無法從 C# 連接到 Azure DevOps Repo

[英]Unable to connect to Azure DevOps Repo from C#

我有一個 web api 連接到 azure devops repo 並檢索一些文件來執行一些操作。 問題是,我無法從 web 服務連接。 我收到錯誤“SocketException:連接嘗試失敗,因為連接方在一段時間后沒有正確響應,或者建立連接失敗,因為連接的主機沒有響應”。 但是,相同的代碼在控制台應用程序中運行得非常好。

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>

</system.net>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM