我们正在尝试使用 Azure 市场上提供的 Microsoft 翻译服务。我从http://code.msdn.microsoft.com/windowsazure/Walkthrough-Translator-in-7e0be0f7/view/SourceCode提供的示例代码开始
使用他们的示例代码,我可以获得一个翻译。但是,我想在一个请求中获得多个翻译。我尝试使用 DataServiceContext.ExecuteBatch,但它抛出 WebException 并显示“远程服务器返回错误:(404)未找到。”
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);
我可以使用多个线程并并行发出多个请求。但我喜欢避免这种情况。以前有人试过吗?