Silverlight, Web Services and Datasets

G05B0037 I sat down today to learn about using Silverlight and Dataset from a Web Service.  Something you’d think would be rather trivial.

I mean, seriously folks.  We use Datasets as a means of transporting data up and down the tiers of just about everything we do in .NET.  It would stand to reason that using DataSets as our transport mechanism in Silverlight would be a given.

But no.  We have to jump through all kinds of hoops.

In fact, if you try to return a DataSet or a DataTable you won’t get any data.  If you try to return a DataRow, you’ll get an error.

Instead you have to stick with certain classes or decorate your own class with some attributes.

So let me get this straight.  If I want to return several records from a table back to my Silverlight application, I have to:

  1. Create a new class with properties that map to my table.
  2. Decorate that class with the appropriate attributes so that it will get serialized back to Silverlight correctly.
  3. Do my own database access
  4. Create the new “Row Objects” with my class and add them to a collection
  5. Return the collection from my web method to my Silverlight application

Um, isn’t that what Datasets were created for?  Am I missing something?  Somebody, PLEASE tell me I’m missing something!

Related Post

  • Silverlight – Databinding to a Web ServiceSilverlight – Databinding to a Web Service In the last several posts, I’ve demonstrated various ways of getting data onto the screen.  What I’ve purposely omitted up until this point is how to update this information. So let’s start ...
  • Installing Silverlight2 Tools for Visual StudioInstalling Silverlight2 Tools for Visual Studio I was talking with a friend of mine a couple of days ago about the future of web development and XAML specifically when he made the comment about the tools not being available for the average deve...
  • Silverlight – Navigating DataSilverlight – Navigating Data Last week I demonstrated how to access data from a web service in Silverlight and display it on the page.  Today we are going to continue on with that demo and look at how to navigate through...
  • Silverlight – Binding ResourceDictionariesSilverlight – Binding ResourceDictionaries In the last two Silverlight posts I've introduced databinding in Silverlight.  We've seen that databinding, while similar to what we've experienced in Windows Forms and ASP.NET applications, is ma...
  • More on SilverLight Developer InstallationMore on SilverLight Developer Installation If you followed along with the install instructions last week and then went to do some development, you probably noticed that the Visual Studio environment does not allow for WYSIWYG/Drag and Drop...
  • http://inquisitorjax.blogspot.com Jax

    Firstly, imo exposing .NET DataSets over services is generally a bad idea, esp when those services are being consumed by non-.NET clients (which true services are meant to cater for)

    as for why they haven’t included the DataSet in Silverlight, you’d have to ask the guys at Microsoft. (I can’t say that I miss them all that much – well defined objects are way better for Binding, business logic etc.)

    For a fairly good work-around – check out this post:
    http://silverlight.net/forums/p/16733/63248.aspx

  • http://sarafianalex.wordpress.com Alex Sarafian

    I have the same question.
    Linq is not a solution for n-tier. ADO.NET through WCF is a possibility but what if you don’t want to simply transfer your database front end to the client. What if stored procedures are required.

    DataSet and especially Typed ones are the easiest and quickest way to transfer organized and related data over the wire.

    Why have they put aside this great mechanism?

  • Dave

    Jax,

    We are going to have to agree to disagree. Specifically about “well defined object are way better for Binding…”

    There are specific features of databinding that you lose when you don’t use datasets.

  • Brian

    I having a similar problem with accessing stored procedures in our database, that returns data from a cross-join, with X number of columns.

    When I go to show the ado data service in the browser, I get a Request Error – The server encountered an error processing the request. See server logs for more details.

    What’s a good approch for dealing with this type of dynamic data?

    Thanks for you help,

  • Dave

    Look in the event logs (event viewer) chances are there is an error about the time you did this that will tell you exactly what the problem is.