Feed Icon  


  • Bryant Likes
  • Send mail to the author(s) E-mail
  • twitter
  • View Bryant Likes's profile on LinkedIn
  • del.icio.us
Get Microsoft Silverlight
by clicking "Install Microsoft Silverlight" you accept the
Silverlight license agreement

Hosting By

Hot Topics


Open Source Projects



Consuming Astoria from Silverlight

Posted in Silverlight at Monday, 28 January 2008 02:28 Pacific Standard Time

Michael Sync wrote a great tutorial on how to consume ADO.Net Data Services (Astoria) from Silverlight. I just demoed Silverlight on top of Astoria at code camp and wanted to add one comment to Michael's post:

Create the class like below. (Note: The class name should be the same as your table name. The fields should be the same as your table structure.)

  1. public class Customer {  
  2. public int CustomerID { get; set; }  
  3. public string CustomerName { get; set; }  
public class Customer {
public int CustomerID { get; set; }
public string CustomerName { get; set; }

I don’t like to create that class in Silverlight project but this is by-design issues so that I have no choice. I hope Astoria Team will do something about it.

Actually you do have a choice, and it is much simpler. If you read the ADO.NET Data Services Quickstart on the .NET Client Library, about a quarter of the way down there is a section on using the Webdatagen tool:

Webdatagen.exe is located in the directory \Program Files\Microsoft ASP.NET 3.5 Extensions. The tool takes an argument: the base URL to the data service for which types are to be generated. For example, if the Northwind service is running in the Visual Studio development server at http://localhost:1234/Northwind.svc, the command line to generate classes for it is:

\Program Files\Microsoft ASP.NET 3.5 Extensions\WebDataGen.exe"  /mode:ClientClassGeneration /outobjectlayer:northwind.cs /uri:http://localhost:1234/Northwind.svc

The output from the command is a C# file (Visual Basic types can be generated using the /language:VB switch) that contains a class for each of the entity types in the data service.

So instead of creating all your own classes, simply use the webdatagen tool to generate them for you. There is one minor change you will need to make to the generated code: you will need to comment out the Serializable attribute on all the generated classes. Other than that it works like a charm.

Comments are closed.