Devs4Devs Presentation: Pushing Data to Silverlight over HTTP

On 9 May 2009 I presented at a developer event called Devs4Devs. It’s an event run by Microsoft that invites new speakers to present at a small forum to help unearth new speaking talent for events like DevDays and TechEd.

Public speaking has always been something of a challenge for me, so I decided to push myself and give it a go. I presented a session on pushing data to a Silverlight client over HTTP. I’d worked with this on a project for a customer recently and thought this would be an interesting topic.

The session went pretty well and, despite the nerves, I actually enjoyed myself. I got some good feedback from the attendee evaluations and from Eben (the event organizer). I’m hoping this will help build my confidence and experience in public speaking.

 

About the Presentation

The idea I wanted to talk about is how to use a new WCF binding provided in the Silverlight 2.0 SDK to create a service that can establish a two-way (i.e. duplex) communication with a client over HTTP. HTTP is a request-response protocol and doesn’t allow data to be transferred from the server to the client unless the client has requested it.

I wanted to explore more deeply how this is done with Silverlight (the binding is essentially doing some intelligent polling under the covers for you) but the session was only 20 minutes long, so I had to be brief.

To demonstrate the topic I wrote a service to simulate a random IPL cricket match* (since that’s all the rage at the moment in South Africa). The service generates events for a cricket game and sends out scoreboard updates to any clients that have connected to the service. The client simply binds the scoreboard data to UI elements to display batting and bowling statistics and provide a ball-by-ball commentary (like CricInfo).

Devs4Devs Silverlight Scoreboard 1 Devs4Devs Silverlight Scoreboard 2

My session walked through creating the service and the client in Silverlight 2.0 and showed the awkward asynchronous channel programming model required to get the client to communicate with the service.

I then walked through the improvements that will be coming in Silverlight 3.0 to improve the programming model by showing how the code as implemented using Silverlight 3.0 Beta.

 

Slide Deck and Source Code

I know it’s a little late but if I’m making the slide deck and source code available online for anyone who is interested. Go ahead and grab ‘em:

  • Slides
  • Code – This includes two solutions: one for Silverlight 2.0 and another using Silverlight 3.0 Beta (version 3.0.40307.0).

Please note that the code is NOT production quality. I purposely tried to keep things simple for the presentation by using synchronous service-side methods and I’ve omitted a lot of error and exception handling code. There are also a few bugs in the cricket match simulator and probably plenty more that I haven’t discovered. Use it to learn, but not for anything real and use it at your own risk!

To open the solutions and run the code you’ll need: either Silverlight Tools for Visual Studio 2008 SP1 (for opening and compiling the Silverlight 2.0 solution) or Silverlight 3 Beta Tools for Visual Studio (for opening and compiling the Silverlight 3.0 Beta solution).

Note: Silverlight 3.0 projects are not compatible with Silverlight 2.0 projects. If you install the Silverlight 3.0 Beta Tools for Visual Studio you will be unable to open Silverlight 2.0 projects. I recommend installing the Silverlight 3.0 tools in a separate environment.

 

Other Resources

I’ll try and post a few articles about the code to explain the technique a bit more, but there is a lot of great content out there already:

 

– Dario

 

* The simulation was fun to write (although the code is butt ugly)! I didn’t want to spend too much time on it and after I got started I realized that simulating a cricket game is harder than I originally thought. There are just so many different events in a cricket game and different things that can happen. The simulation engine takes some short-cuts and definitely isn’t complete. I make no apologies, it was written in a hurry and wasn’t really the focus of the session.