BuildIt.CognitiveServices.CognitiveServiceClient.KeyPhrasesApiRequestAsync C# (CSharp) Method

KeyPhrasesApiRequestAsync() public method

The API returns a list of strings denoting the key talking points in the input text. We employ techniques from Microsoft Office's sophisticated Natural Language Processing toolkit.
public KeyPhrasesApiRequestAsync ( string subscriptionKey, string jsonString, string contentType = Constants.DefaultContentType ) : Task>
subscriptionKey string
jsonString string Request body
contentType string Media type of the body sent to the API.
return Task>
        public async Task<ResultDto<KeyPhrasesApiFeeds>> KeyPhrasesApiRequestAsync(string subscriptionKey,
            string jsonString, string contentType = Constants.DefaultContentType)
        {
            var resultDto = new ResultDto<KeyPhrasesApiFeeds>();
            try
            {
                var client = new HttpClient();
                client.DefaultRequestHeaders.Add(Constants.SubscriptionTitle, subscriptionKey);
                HttpResponseMessage response;

                // Request body
                var byteData = Encoding.UTF8.GetBytes(jsonString);

                using (var content = new ByteArrayContent(byteData))
                {
                    content.Headers.ContentType = new MediaTypeHeaderValue(contentType);
                    response = await client.PostAsync(Constants.KeyPhrasesApi, content);
                }
                var jsonResult = await response.Content.ReadAsStringAsync();
                var feed = JsonConvert.DeserializeObject<KeyPhrasesApiFeeds>(jsonResult);

                resultDto.Result = feed;
                resultDto.ErrorMessage = feed.message;
                resultDto.StatusCode = feed.statusCode.ToString();
                foreach (var error in feed.errors)
                {
                    resultDto.ErrorMessage += $"InnerError :{error.message}";
                    resultDto.StatusCode += $"InnerErrorCode :{error.id}";
                }
                resultDto.Success = string.IsNullOrEmpty(feed.message);
            }
            catch (Exception ex)
            {
                resultDto.ErrorMessage = ex.Message;
                resultDto.Exception = ex;
                Debug.WriteLine($"Error: {ex}");
            }
            return resultDto;
        }