Translate To French Service · Server Code


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace MyWebService
{
    /// <summary>
    /// Summary description for TranslateToFrenchService
    /// </summary>
    [WebService(Namespace = "http://rodansotto.com/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script,
    //  using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class TranslateToFrenchService : 
        System.Web.Services.WebService
    {
        private string[,] translations =
        {
            {"good morning", "bonjour"},
            {"good evening", "bonsoir"},
            {"thank you", "merci"},
            {"please", "s'il vous plait"},
            {"welcome", "bienvenue"},
            {"goodbye", "au revoir"},
            {"see you soon", "à bientôt"}
        };

        [WebMethod]
        public string TranslateToFrench(string english)
        {
            for (int i = 0; i < translations.GetLength(0); i++)
            {
                if (string.Compare(
                    english, translations[i, 0], true) == 0)
                {
                    return translations[i, 1];
                }
            }
            return "";
        }
    }
}