Rx: Bing Translate Example

In his Rx session at PDC09 Eric Meijer gave a nice example named Bing Translate. It was connecting to Bing via the Bing Web Service API and translated some term given by the user. It was quite interesting because Eric used the Reactive Framework for handling the translation and did some composition of the incoming results. He took just the first 2 translations and discarded the others. This didn’t make much sense, but it was ok for demonstration purposes. As followup Somasegar described the example in his blog.

But there was a lack of the whole sourcecode (btw: Eric Meijer posted it now on the Rx forum, but not as VS solution) and so I implemented it on my own with some modifications and now I want to share the whole Visual Studio solution with you.

Live demo

I’ve put my Bing Translate example as SL3 application on Windows Azure at http://bingtranslate.cloudapp.net, where you can directly test it:

Rx Bing Translate Example - Reactive Extensions - Reactive Framework

Sourcecode requirements

Since the Bing Translate example uses the Bing Web Service API, you need to get a free AppId here. Additional information on the Bing API can be found on the Bing Developer Center. When you’ve obtained your AppId, insert it into the BingService.cs file (field AppId of class BingService) of the sourcecode below. Now you should be able to run the solution.

What you furthermore need to open and run the solution:

  • Visual Studio 2008
  • Silverlight 3 SDK
  • Reactive Extensions for SL3 (latest release)

Now give me the code!

Ok, you want it, you get it 😉

[Visual Studio Solution for Silverlight 3 (ZIP)]

Notes on the code:

  • Contrary to Eric’s solution, mine will not synchronize the translation events when using the SetUpTranslationService() method in the MainPage.xaml.cs file. Use the SetUpTranslationServiceWithJoin() method if you want to have some synchronization. The main advantage of Rx is the composition of event streams, so this synchronization shows how simple things could be.
  • The code’s style is not expressing my real coding skills. Since this is just an example project, I did not make it stylish and bullet-proof.

That’s it! Have fun and please feel free to give me feedback.

kick it on DotNetKicks.com

2 Gedanken zu „Rx: Bing Translate Example“

  1. I get the following error, what do i have to do?
    i have referenced the BingTranslate.ServiceReference1
    but this method is still missing do i have to reference something else?

    Error 1 The type or namespace name ‚LiveSearchPortTypeClient‘ could not be found (are you missing a using directive or an assembly reference?) C:\Users\Administrator\Desktop\BingTranslate\BingTranslate\BingService.cs 39 31 BingTranslate

  2. Hi Alex and thanks for your feedback,

    I’ve tried my own solution on another computer and it just works. You do not have to add a service reference, the service reference is already there (in the BingTranslate project)!
    All you have to do is:
    1) unzip,
    2) enter your AppId (get yours from http://www.bing.com/developers/createapp.aspx) in BingService.AppId (Constants region in BingService.cs file)
    3) run and done 🙂

    I hope this helps.
    ~ Matthias

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.