Using the Silverlight 4.0 WCF Data Services Client Library

DB Blogs

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 hereSilverlight 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.

clip_image002

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.

Steps:

In the Solution Explorer click the Show All Files button.

clip_image004

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:

clip_image006

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

System.Data.Services.Client.DataServiceCollection.Create<EntitySetName>();

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

0 comments

Discussion is closed.

Feedback usabilla icon