-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathGetLanguagesForSpeakMethod.cs
More file actions
73 lines (67 loc) · 2.49 KB
/
GetLanguagesForSpeakMethod.cs
File metadata and controls
73 lines (67 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Web;
namespace MicrosoftTranslatorSdk.SoapSamples
{
class Program
{
static void Main(string[] args)
{
AdmAccessToken admToken;
string headerValue;
//Get Client Id and Client Secret from https://datamarket.azure.com/developer/applications/
AdmAuthentication admAuth = new AdmAuthentication("clientId", "clientSecret");
try
{
admToken = admAuth.GetAccessToken();
DateTime tokenReceived = DateTime.Now;
// Create a header with the access_token property of the returned token
headerValue = "Bearer " + admToken.access_token;
GetLanguagesForSpeakMethod(headerValue);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine("Press any key to continue...");
Console.ReadKey(true);
}
}
private static void GetLanguagesForSpeakMethod(string authToken)
{
string uri = "http://api.microsofttranslator.com/v2/Http.svc/GetLanguagesForSpeak";
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(uri);
httpWebRequest.Headers.Add("Authorization", authToken);
WebResponse response = null;
try
{
response = httpWebRequest.GetResponse();
using (Stream stream = response.GetResponseStream())
{
System.Runtime.Serialization.DataContractSerializer dcs = new System.Runtime.Serialization.DataContractSerializer(typeof(List<string>));
List<string> languagesForSpeak = (List<string>)dcs.ReadObject(stream);
Console.WriteLine("The languages available for speak are: ");
languagesForSpeak.ForEach(a => Console.WriteLine(a));
Console.WriteLine("Press any key to continue...");
Console.ReadKey(true);
}
}
catch
{
throw;
}
finally
{
if (response != null)
{
response.Close();
response = null;
}
}
}
}
}