Previously there the bing translator was easily accessible with the SOAP interface. Now it has been migrated to Windows Azure. I have registered in the Azure marketplace for 10000 letters per month (free). How can I translate text through the translator api, for windows phone in C#? Please help. I am not sure how to use the BeginExecute and EndExecute for queries.
I have downloaded and added the TranslatorContainer.cs to my project. For now I am just trying to get the Languages with the GetLanguagesForTranslation method. This is the code which I have written.
public partial class PhonePage1 : PhoneApplicationPage
{
public PhonePage1()
{
InitializeComponent();
Translator transInstance = new Translator();
}
class Translator
{
private Uri service_root;
private TranslatorContainer context;
public Translator()
{
service_root = new Uri("https://api.datamarket.azure.com/Bing/MicrosoftTranslator/");
context = new TranslatorContainer(service_root);
context.Credentials = new NetworkCredential("ID","...........");
var query = context.GetLanguagesForTranslation();
query.BeginExecute(OnQueryComplete, query);
}
public void OnQueryComplete(IAsyncResult result)
{
var query = result as DataServiceQuery<Language>;
string langstring = "";
foreach (Language lang in query.EndExecute(result))
{
langstring += lang.Code + "\n";
}
MessageBox.Show(langstring);
}
}
}
In OnQueryComplete() the query
is null even after the assignment. The result has the Properties IsCompleted as true, and statusCode is OK.
I am not able to figure out how to go about this. Please help.
Thank you