We are trying to use Microsoft translation service provided on Azure market place. I started with the sample code provided at http://code.msdn.microsoft.com/windowsazure/Walkthrough-Translator-in-7e0be0f7/view/SourceCode
Using their sample code I can get a single translation. However I would like to get multiple translations in a single request. I tried using DataServiceContext.ExecuteBatch but it throws WebException with "The remote server returned an error: (404) Not Found."
TranslatorContainer cont = new TranslatorContainer(new Uri("https://api.datamarket.azure.com/Bing/MicrosoftTranslator/"));
var accountKey = "<account-key>";
cont.Credentials = new NetworkCredential(accountKey, accountKey);
// This works
var result1 = cont.Translate("Nothing to translate", "nl", "en").Execute().ToList();
DataServiceQuery<Translation>[] queries = new DataServiceQuery<Translation>[]
{
cont.Translate("Nothing", "nl", "en"),
cont.Translate("Nothing to translate", "nl", "en"),
cont.Translate("What happend", "nl", "en"),
};
// This throws exception
var result2 = cont.ExecuteBatch(queries);
I could use multiple threads and make multiple requests in parallel. But I like to avoid that. Anyone have tried this before ?
I’m not sure why your code doesn’t work. But you may want to use the REST API directly. Please try to use the following code which works fine on my side:
The result is an AtomPub feed. You can then parse the feed (for example, use SyndicationFeed class: http://msdn.microsoft.com/en-us/library/system.servicemodel.syndication.syndicationfeed.aspx).
Best Regards,
Ming Xu.
Use this NuGet package for batch translation on CognitiveServices Translator API 3.0
Here are steps:
Create an instance of Translator with your BaseUrl and Key:
Add content to the Translator:
Get results aysnc: