我打算使用Microsoft的翻译服务构建网站。我需要为每个单词获得所有可用的翻译,但我提供的代码只提供一个翻译,而它应该提供所有可用的翻译。这是代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using microsofttranslator;
using System.Text;
using System.Net;
using System.IO;
using System.Runtime.Serialization.Json;
using System.Runtime.Serialization;
using System.ServiceModel.Channels;
using System.ServiceModel;
using TranslatorService;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{string Appid="my Appid";
string t="any text";
microsofttranslator.TranslateOptions options = new microsofttranslator.TranslateOptions();
options.Category = "general";
options.ContentType = "text/plain";
options.User = "TestUserId";
options.Uri = "";
bool a=true;
SoapService s = new SoapService();
microsofttranslator.GetTranslationsResponse translations = s.GetTranslations(Appid, t, "ar", "en", 5,a, options);
Response.Write(string.Format("Available translations for source text '{0}' are", t));
foreach (microsofttranslator.TranslationMatch translationMatch in translations.Translations)
{
Response.Write(string.Format("Translated text: {0}" + Environment.NewLine + " Rating:{1}" + Environment.NewLine + "Count:{2}" + Environment.NewLine, translationMatch.TranslatedText, translationMatch.Rating.ToString(), translationMatch.Count.ToString()));
} }}
我添加了Microsft翻译WSDL作为网络参考http://api.microsofttranslator.com/v2/Soap.svc?wsdl,我添加了TranslatorService作为服务参考http://api.microsofttranslator.com/V2/Soap.svc
这段代码效果很好但正如我所说它只提供一个翻译,而它应该提供一个单词的所有可用翻译。我无法弄清楚我做错了什么。
答案 0 :(得分:0)
也许你应该使用" translateArray"方法