请求只是挂起

Request just hangs

获取分析器列表的请求挂起。具体 > return Client.ListAnalyzersAsync().Result 这最终调用了一个 http 客户端请求。

我的代码直接来自示例应用程序。还是没有爱。感谢帮助

这里是LinquisticClient库中默认的url

私有常量字符串 DefaultServiceHost = "https://api.projectoxford.ai/linguistics/v1.0";

这是我创建的class

我调用的是这个方法 - Parse()

public static class LinguisticAnalyzer
{
    private static readonly LinguisticsClient Client = new LinguisticsClient("Removed_id");

    public static string Parse(string line)
    {
        // List analyzers
        Analyzer[] supportedAnalyzers = null;
        try
        {
            supportedAnalyzers = ListAnalyzers();
            var analyzersAsJson = JsonConvert.SerializeObject(supportedAnalyzers, Formatting.Indented, jsonSerializerSettings);
            Console.WriteLine("Supported analyzers: " + analyzersAsJson);
        }
        catch (Exception e)
        {
            Console.Error.WriteLine("Failed to list supported analyzers: " + e.ToString());
            Environment.Exit(1);
        }

        // Analyze text with all available analyzers
        var analyzeTextRequest = new AnalyzeTextRequest()
        {
            Language = "en",
            AnalyzerIds = supportedAnalyzers.Select(analyzer => analyzer.Id).ToArray(),
            Text = line //"Welcome to Microsoft Linguistic Analysis!"
        };

        try
        {
            var analyzeTextResults = AnalyzeText(analyzeTextRequest);
            var resultsAsJson = JsonConvert.SerializeObject(analyzeTextResults, Formatting.Indented, jsonSerializerSettings);
            Console.WriteLine("Analyze text results: " + resultsAsJson);

            return resultsAsJson;
        }
        catch (Exception e)
        {
            Console.Error.WriteLine("Failed to list supported analyzers: " + e.ToString());
            Environment.Exit(1);
        }

        return "";
    }

    /// <summary>
    /// Default jsonserializer settings
    /// </summary>
    private static JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings()
    {
        DateFormatHandling = DateFormatHandling.IsoDateFormat,
        NullValueHandling = NullValueHandling.Ignore,
        ContractResolver = new CamelCasePropertyNamesContractResolver()
    };

    /// <summary>
    /// List analyzers synchronously.
    /// </summary>
    /// <returns>An array of supported analyzers.</returns>
    private static Analyzer[] ListAnalyzers()
    {
        try
        {
            return Client.ListAnalyzersAsync().Result;
        }
        catch (Exception exception)
        {
            throw new Exception("Failed to gather list of analyzers", exception as ClientException);
        }
    }

    /// <summary>
    /// Analyze text synchronously.
    /// </summary>
    /// <param name="request">Analyze text request.</param>
    /// <returns>An array of analyze text result.</returns>
    private static AnalyzeTextResult[] AnalyzeText(AnalyzeTextRequest request)
    {
        try
        {
            return Client.AnalyzeTextAsync(request).Result;
        }
        catch (Exception exception)
        {
            throw new Exception("Failed to analyze text", exception as ClientException);
        }
    }

}

事实证明这是 C# 客户端库的问题,而不是服务本身的问题。可以在 GitHub.

上找到更多信息