2012-03-13 29 views
-1

我要建立的網站使用微軟的翻譯服務。我需要爲每個單詞獲取所有可用的翻譯,但我提供的代碼只提供一個翻譯,而它應該提供所有可用的翻譯。下面的代碼:使用Microsoft翻譯(GetTranslation服務)

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作爲Web參考http://api.microsofttranslator.com/v2/Soap.svc?wsdl和我說TranslatorService作爲服務引用http://api.microsofttranslator.com/V2/Soap.svc

此代碼的工作很好,但我說這僅給出了一個翻譯,而這是應該給所有可用的單詞翻譯。我無法弄清楚我做錯了什麼。

+0

API文檔說:「所有可用的」,而不是「所有可能的」 ......無論是不止一個(多少)的翻譯給定字/文本在MS翻譯記憶只存在是什麼MS可以回答...我懷疑對於你嘗試過的文本/語言,它只包含一個翻譯... – Yahia 2012-03-13 16:07:52

+0

@Yahia是的我知道它說所有可用,並不是所有可能..但我嘗試了這麼多的話,但它只給出一個翻譯! – Nina 2012-03-13 16:45:09

回答