调用web service实现翻译功能

1.新建窗体应用程序

2.添加二个输入文本框,txtTranslateFrom,txtTranslatedText 设置多行属性为真.

3.添加一个btnTranslate按钮

4.添加Service Reference引用,http://api.microsofttranslator.com/V1/SOAP.svc

命名为TranslatorService

5.想调用bing的翻译功能Web Service需要一个APPID,可以到http://www.bing.com/developer上面注册一个.

6.按钮事件:

private void btnTranslate_Click(object sender, EventArgs e)
{
    string strTranslatedText = null;
    try
    {
        TranslatorService.LanguageServiceClient client = new TranslatorService.LanguageServiceClient();
        client = new TranslatorService.LanguageServiceClient();
        strTranslatedText = client.Translate("your App ID", txtTraslateFrom.Text, "", "en");
        txtTranslatedText.Text = strTranslatedText;
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}
Translate的四个参数
posted @ 2010-01-19 14:56  smodi  阅读(463)  评论(0编辑  收藏  举报