Using the Silverlight 4.0 WCF Data Services Client Library

Recently Microsoft released Silverlight 4 Beta which includes an update to the Data Services Silverlight client. The update includes most of the new features previewed in the ADO.NET Data Services CTP2 - see this blog post for a complete list of the features in CTP2. The new Silverlight 4.0 Data Services client library also includes improvements to the databinding feature to make binding in an asynchronous environment easier and enhanced support for cross-domain calls in Silverlight.

The Silverlight 4.0 beta can be downloaded here - Silverlight 4.0 is designed to be used with Visual Studio Beta 2 only which can be downloaded here.

Using the SL4 Beta Client in Visual Studio 2010 Beta 2

Using the Visual Studio 2010 Beta 2 Add Service Reference feature with the Silverlight 4.0 beta requires a few extra steps from the normal process – these steps are only necessary for Visual Studio Beta 2 and will not be necessary in the RTM version of Visual Studio 2010. The following steps assume that you have setup your data service and created your Silverlight application – if you are new to Silverlight and Data Services you can follow the directions here to create your SL application.

Once you have the service and Silverlight application created, the first step is to add a service reference from the Silverlight client. Right-click the Silverlight application project in the Solution Explorer and select Add Service Reference… Fill in the address of the service root, enter a namespace for the service reference and click OK.


The service reference will be created. Press F6 to compile the project – you will see some compilation errors in the service reference. At this point, you have to perform a couple of extra steps to resolve the compilation errors.


In the Solution Explorer click the Show All Files button.


A small gray arrow will now be displayed next to your service reference. Expand your service reference, and then expand the Reference.datasvcmap file. Double-click the Reference.cs file that is within the Reference.datasvcmap file node in the solution explorer to open the service reference code.

In the errors output window of Visual Studio, you will see number of errors in this file like the one shown here:


To resolve these errors, for each entity type in your service, you need to perform a search and replace in the reference.cs file. Search for (being sure, when searching to replace entitytypename with the name of the entity type you are searching for):


And replace each instance found with:

new System.Data.Services.Client.DataServiceCollection<EntitySetName>(null, System.Data.Services.Client.TrackingMode.None);

Press F6 to compile; the error message should now be gone. If you update the service reference you will need to repeat these steps.


Shayne Burgess

Program Manager, Data Services, Microsoft

Comments (5)

  1. Shayne, thank you very much for sharing that. This brings light in the dark (as we say in Germany 😉 ) and it works.

    If the refreshrate of the Servicereference through the development-cycle is high, i would also recommend an alternative to the coe-replacement:

    Just remove the System.Data.Services.Client.dll from the references and add the Microsoft.Data.Services.Client.dll which you can download with the ADO.NET Data Services CTP2. There the static Create-Method exists and you haven’t to replace anything.

  2. KierenH says:

    What’s the roadmap for Data Services? Are you guys going to handle change tracking automagically for us?

    Currently using 1.5 CTP 2 – is there, or will there be anotehr drop for SL3?

  3. Alexander Bartosh says:

    Search and Replace dialog (Ctlr+H)

    Find What:


    Replace With:

    new System.Data.Services.Client.DataServiceCollection<1>(null, System.Data.Services.Client.TrackingMode.None)

    Use: Regular expressions

  4. Greg Neilson says:

    Or, if you’re trying to do this within some C# code (perhaps some sort of automated build environment), you need this:

               Regex rr = new Regex("System.Data.Services.Client.DataServiceCollection.Create<(.*)>\(\)");

               allText = rr.Replace(allText, "new System.Data.Services.Client.DataServiceCollection<$1>(null, System.Data.Services.Client.TrackingMode.None)");

    That should get you going. VS find and replace regex syntax is different to the .net syntax.

  5. frank patton says:

    i am deploying a very simple vs2010 adonet silverlight 4 app .. it works fine on my laptop, with the data coming from discountasp, but when i run the published app on discountasp, the app works, does not freese up, or bomb out, but no data comes through .. any ideas? I am getting desperate ..

Skip to main content