dir.by  
  Search  
Programming, development, testing
Microsoft Azure & Azure DevOps (облачные технологии)
Write a C# console application to translate text using Azure Translators
  Looked at 2915 times    
 Write a C# console application to translate text using Azure Translators 
last updated: 17 April 2024
  C#     Program.cs
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json; // Install Newtonsoft.Json with NuGet

namespace ConsoleApp1
{
     class Program
     {
          // my settings !!!
          private static readonly string endpoint = "https://api.cognitive.microsofttranslator.com/";
          private static readonly string subscriptionKey = "568af7141d8e4f309f712d.............";
          private static readonly string location = "westeurope";

          // program
          static async Task Main(string[] args)
          {
               // Input and output languages are defined as parameters.
               string route = "/translate?api-version=3.0&from=en&to=de&to=it";
               string textToTranslate = "Hello, world!";
               object[] body = new object[] { new { Text = textToTranslate } };
               var requestBody = JsonConvert.SerializeObject(body);

               using (var client = new HttpClient())
               using (var request = new HttpRequestMessage())
               {
                    // Build the request.
                    request.Method = HttpMethod.Post;
                    request.RequestUri = new Uri(endpoint + route);
                    request.Content = new StringContent(requestBody, Encoding.UTF8, "application/json");
                    request.Headers.Add("Ocp-Apim-Subscription-Key", subscriptionKey);
                    request.Headers.Add("Ocp-Apim-Subscription-Region", location);

                    // Send the request and get response.
                    HttpResponseMessage response = await client.SendAsync(request).ConfigureAwait(false);
                    // Read response as a string.
                    string result = await response.Content.ReadAsStringAsync();
                    Console.WriteLine(result);
               }
          }
     }
}
Example result
"endpoint", "subscriptionKey", "location" we take from here:
 
← Previous topic
Create Azure Translators (to translate text)
 
Next topic →
Azure Translator error "is disabled and therefore marked as read only. You cannot perform any write actions on this subscription until it is re-enabled"
 
Your feedback ... Comments ...
   
Your Name
Your comment (www links can only be added by a logged-in user)

  Объявления  
  Объявления  
 
Azure
Что такое Microsoft Azure ?
Как создать сервис в Azure ?

Azure (Subscription)
Создаем Subscription в Azure
Как посмотреть расходы (сколько денег платить в месяц, оплатить) в Azure ?
Как поменять billing card number в Azure

Устанавливаем на телефоне программу Microsoft Authenticator
Устанавливаем на телефоне программу Microsoft Authenticator и входим в учетную запись

Azure (Resource Group)
Создаем Resource Group в Azure

Azure (SQL Server)
Создаем SQL Server в Azure
Пишем C# программу для использования базы данных SQL Server Azure
Сохраняем базу данных SQL Server Azure на свой компьютер (backup)
В базе данных SQL Server Azure устанавливаем самую дешевую цену (6$ в месяц Basic)

Azure (Web service) для .Net Core 5.0 приложения
Создаем Azure Web service с типом Net Core 5. То есть создаем пустой web server с типом Net Core 5
Приложение .Net Core 5 Web Api делаем publish в → Azure | используем Visual Studio 2019
К приложению .NET Core 5 Web API (Azure Web Service) соединяемся через FTP | используем FAR, File Explorer
Azure (Web App) для Angular 9.0 приложения
Создаем Azure Web Service для Angular приложения. То есть создаем пустой web server
Приложение Angular web application делаем publish в → Azure | используем Visual Studio Code
К приложению Angular (Azure Web Service) соединяемся через FTP | используем FAR, File Explorer
Azure Translators (Translator)
Create Azure Translators (to translate text)
Write a C# console application to translate text using Azure Translators
Azure Translator error "is disabled and therefore marked as read only. You cannot perform any write actions on this subscription until it is re-enabled"
Twilio SendGrid (email)
Создаем Azure Twilio SendGrid (для отправки email)
Открывем Twilio SendGrid из Azure. Создаем ApiKey. Пишем c# приложение для отправки email

FTPS Server on Azure
FTPS Server on Azure

Teams plug-in application
Создаем новое приложение "Microsoft Teams web application (plug-in)" using React
Создаем Azure Web Service для React Teams web application. То есть создаем пустой web server
Приложение .Microsoft Teams web application делаем publish в → Azure | используем Visual Studio Code
Upload app in teams

Добавляем пользователя
Добавляем нового пользователя и чтобы пользователь имел доступ на Subscription
Azure DevOps
Что такое Azure DevOps ?

В DevOps создаем организацию. Создаем проекты
Начать работу с Azure DevOps. Создаем организацию. Создаем проект (git репозиторий)

В DevOps приглашаем пользователя
В DevOps приглашаем пользователя
В DevOps назначем приглашенному пользователю права (чтобы приглашенный пользователь мог зайти в devops)

Еще о DevOps
Цена на Azure DevOps
Зайти в Azure DevOps через браузер Chrome
Что содержит Azure DevOps в браузер Chrome ?
Azure DevOps. Коммитим файлы в git используя Team Explorer в Visual Studio 2017
Azure DevOps. Как добавить в баг ссылку на git commit (используем commit hash)

  Ваши вопросы присылайте по почте: info@dir.by  
Яндекс.Метрика