<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<div>
<asp:updatepanel id="UpdatePanel12" runat="server">
<ContentTemplate>
<div style="position: relative;width: 324px; margin-left: 20px; margin-top:20px;
margin-bottom:20px;">
<asp:Label ID="lblPart1" runat="server" Width="359px" Text="Click to see the list of
support languages:"></asp:Label>
</div>
<!-- Button and click event to get the language culture codes via the HTTP API -->
<div style="position: relative;width: 167px; margin-left: 10px; margin-bottom:20px;">
<asp:Button ID="btnShowLanguageCodes" runat="server" Text="Show Culture Codes"
onclick="btnShowLanguageCodes_Click" />
</div>
<!-- Label for the result of the btnShowLanguageCodes event -->
<div style="position: relative; width: 324px; margin-left:20px; margin-bottom:10px;">
<asp:Label ID="lblOutput1" runat="server" Width="602px"></asp:Label>
</div>
<div style="position: relative;width: 324px; margin-left: 20px; margin-top:20px;
margin-bottom:20px;">
<asp:Label ID="lblInstructions" runat="server" Width="359px" Text="Click to see the list of
support languages:"></asp:Label>
</div>
<!-- Button and click event to get the language names via the HTTP API -->
<div style="position: relative;width: 167px; margin-left: 10px; margin-bottom:20px;">
<asp:Button ID="btnShowLanguages" runat="server" Text="Show Language Names"
onclick="btnShowLanguages_Click" />
</div>
<!-- Label for the result of the btnShowLanguages event -->
<div style="position: relative; width: 324px; margin-left:20px; margin-bottom:10px;">
<asp:Label ID="lblOutput2" runat="server" Width="602px"></asp:Label>
</div>
<fieldset>
<legend>Results</legend>
<table>
<tr>
<td>
Using Microsoft's Translator HTTP API you can easily get the full list of
supported language names and culture codes, this is achieved through a
simple web request to the GetLanguages or GetLanguageNames methods of the
API's web service.
</td>
<tr />
<tr />
<tr>
<td>
Clicking the above buttons will create a web request to the associated
method, read the response into a string and display it in a label on the
page. These methods are powerful when used in conjunction with the Detect
method to display the full language name over just the culture code - an
example of this is covered in the SOAP demos. Click the Code-Behind tab
to see how to make a request to these two methods.
</td>
</tr>
</table>
</fieldset>
</ContentTemplate>
</asp:updatepanel>
</div>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.IO;
namespace InteractiveSDK.HTTP
{
public partial class HTTPDemo3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
// Click event for the first button
protected void btnShowLanguageCodes_Click(object sender, EventArgs e)
{
// Create a web request to the HTTP API web service
// Add the appId parameter to the request URL
WebRequest req = System.Net.WebRequest.Create(
@"http://api.microsofttranslator.com/V1/Http.svc/GetLanguages?appId=yourAppId");
// Get the response of the web request
WebResponse resp = req.GetResponse();
// Stream and read the web response
Stream strm = resp.GetResponseStream();
StreamReader reader = new System.IO.StreamReader(strm);
// Create a string for the contents of the web response
string locales = reader.ReadToEnd();
// Display the contents of the string in the label
lblOutput1.Text = locales;
}
// Click event for the second button
protected void btnShowLanguages_Click(object sender, EventArgs e)
{
// Create a web request to the HTTP API web service
WebRequest req = System.Net.WebRequest.Create(
@"http://api.microsofttranslator.com/V1/Http.svc/GetLanguageNames?appId=yourAppId");
// Get the response of the web request
WebResponse resp = req.GetResponse();
// Stream and read the web response
Stream strm = resp.GetResponseStream();
StreamReader reader = new System.IO.StreamReader(strm);
// Create a string for the contents of the web response
string languages = reader.ReadToEnd();
// Display the contents of the string in the label
lblOutput2.Text = languages;
}
}
}