title: How to call Bing Translate function in C#?
body: <p>I wrote a metro style application to call bing translator, but it didnt work. I tried to debug this program, but the UI does not respond. I can't figure if it is the URI I am using, or some other problem.</p>
  
  <p>Here my code :</p>
  
  <pre><code>public string GetTranslatedText(string textToTranslate, string fromLang, string toLang)
  {
      string translation;
  
      if (fromLang != toLang)
      {
          string uri = "http://api.microsofttranslator.com/v2/Http.svc/Translate?appId=" +
                      appID + "&amp;text=" + textToTranslate + "&amp;from=" + fromLang + "&amp;to=" + toLang;
  
          HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
  
          try
          {
              WebResponse response = request.GetResponse();
              Stream strm = response.GetResponseStream();
              StreamReader sr = new StreamReader(strm);
              translation = sr.ReadToEnd();
  
              response.Close();
              sr.Close();
          }
          catch (WebException)
          {
              MessageBox.Show("Ensure that you are connected to the internet.",
                          "Translator", MessageBoxButton.OK, MessageBoxImage.Stop);
              return (string.Empty);
          }
      }
      else
      {
          MessageBox.Show("Will not translate to the same language.", "Translator",
                      MessageBoxButton.OK, MessageBoxImage.Exclamation);
          return (string.Empty);
      }
  
      // Parse string into an XElement and get the XElement Value
      // which is returned as the translated text.
      return (XElement.Parse(translation).Value);
  }
  </code></pre>