Showing posts with label web services. Show all posts
Showing posts with label web services. Show all posts

Oct 24, 2007

Talking to the Outside World from Silverlight 1.1: An Introduction

(This post is basically a recap of the introduction part of my REMIX 07 Boston Talk )

Silverlight applications run in the user's browser. We all know about the rich graphics and interactivity that Silverlight provides. But any real-world application will, at some point, need to communicate with the "outside world".

This interaction can take many forms. The simplest one (at least from a developer's point of view) is accessing media from some remote server: you can display an image or play a video from any URL. This capability exists even in the 1.0 version of Silverlight. However, it is limited to only certain types of data - images, videos and sounds.

The next step up is being able to work with arbitrary blobs of data and then write code to make sense of them. In 1.0, your only option was to use JavaScript on the page that hosts your Silverlight control. You could use standard AJAX techniques: use XmlHttpWebRequest to GET any data from some HTTP location and then use JavaScript to adjust your Silverlight graphics accordingly. You could also POST any data to some HTTP location.

In 1.1, there is no need for external JavaScript - you can use the BrowserHttpWebRequest .NET class (a subclass of HttpWebRequest) directly from your Silverlight application to issue GET/POST requests with a Stream of bytes.

But what if you want to work with more than just bytes? Most data has some structure to it: You may be receiving data in XML or JSON format that you will want to parse, or getting an RSS feed that you want to process and then display, or you may be talking to a SOAP service that actually describes its structure using metadata. In other words, you are not just working with bytes but with products, search results or high scores - data that matters to your app. The data may come from a service you yourself create, or from some "mashup-friendly" source like Flickr or Facebook.

This is exactly the problem I am working on within the overall Silverlight effort, and what many of the posts here will be about - how do we make it easy to work with structured data - that is, how do you consume "services" (in the widest sense of the word)? Watch this blog to discover what is planned in this space, and of course leave comments if you have any ideas or feedback!

I should note that most of the information here will be about SL1.1. In the existing SL1.0 (and in 1.1 as well of course) you can use all of the usual AJAX techniques as I already mentioned. In fact, Fritz Onion did a great talk at REMIX on integrating Silverlight 1.0 with ASP.NET AJAX - you can do some pretty powerful things with this combination - check out the Channel9 videos (Parts 1 2 3 4) and sample code.