с помощью Microsoft Translate (Сервис GetTranslation) - PullRequest
0 голосов
/ 13 марта 2012

Я собираюсь создать сайт, который использует сервис перевода от 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 translate WSDL в качестве веб-ссылки http://api.microsofttranslator.com/v2/Soap.svc?wsdl, и я добавил TranslatorService в качестве справочной службы http://api.microsofttranslator.com/V2/Soap.svc

Этот код работает хорошо, нокак я сказал, он дает только один перевод, в то время как он должен дать все доступные переводы слова.Я не могу понять, что я делаю неправильно.

1 Ответ

0 голосов
/ 14 марта 2012

Возможно, вам следует использовать метод translateArray.

http://msdn.microsoft.com/en-us/library/ff512438.aspx

...