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

5 Responses to “Silverlight, Web Services and Datasets”

  • 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:

  • 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:


    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.