请求只是挂起

时间:2017-01-05 20:20:49

标签: microsoft-cognitive

请求获取分析器列表。具体而言>返回Client.ListAnalyzersAsync()。结果 这最终会调用http客户端请求。

我的代码直接来自示例应用。仍然没有爱。感谢帮助

以下是LinquisticClient库中的默认网址

私有const字符串DefaultServiceHost =" https://api.projectoxford.ai/linguistics/v1.0&#34 ;;

以下是我创建的课程

我的呼吁是这个方法 - 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);
        }
    }

}

1 个答案:

答案 0 :(得分:0)

这是C#客户端库的问题,而不是服务本身。有关详细信息,请参阅GitHub