Silverlight: Basic Integration with SharePoint 2010 WCF Data Services
Posted by: Mahesh Sabnis ,
on 10/10/2011,
in
Category Silverlight 2, 3, 4 and 5
Abstract: The advantage of WCF Data Services is that any client application can now make a call to the WCF services and interact with the SharePoint object model. It is not necessary for the end-user to directly log-in to the SharePoint Web Site application and work on it. WCF Data Services provided in SharePoint 2010 helps to implement integration based application with other client applications.
Now beyond writing custom WCF services, you as a developer can very well think of using REST based WCF Data services provided in SharePoint 2010. You can find e.g. ListData.svc in ‘ISAPI’ folder. Using this service, you can implement Silverlight client application for working with SharePoint 2010 web site’s List data.
Here to interact with SharePoint 2010 from Silverlight client, run your application Out-of-Browser.
The WCF Data Service can be found in the following path:
Note: Here MyServer is the name of your SharePoint 2010 Application Host server. Now if you have the SPS 2010 application as Products, then you will find the ListData WCF service in the following path:
Querying the List WCF Data Service
Shown below is a Products Web Collection with a SalesInfo List:
You can browse the WCF Data Service which will Display all Lists in the Web Site collection, using the following URL:
http://mahesh-pc/sites/products/_vti_bin/ListData.svc (change the url with your server name)
The result is as below:
The above marked rectangle shows the SalesInfo List. Now I can query the SalesInfo List to display the entire data using the following URL
http://mahesh-pc/sites/products/_vti_bin/ListData.svc/SalesInfo
The advantage of REST capability is that now any client application Desktop, Web, Browser which can communicate via HTTP and can understand XML, can make a request to the SharePoint 2010 object model (of course with proper Authentication and Authorization) and can interact with the data.
Consuming the SharePoint 2010 WCF List Data Service in Silverlight Client application
This is the main part of this article. The scenario is explained as under:
Since the Silverlight application has to carry the credential information for the SharePoint Web Site collection, to make a call to the WCF Service exposed by SPS 2010, it needs to make use of trusted network credential facility. That’s the reason a Silverlight Out-of-browser client application is used.
Step 1: Open VS2010 and create a Silverlight application, name it as ‘SL4_Consuming_SPS_2010_RestService’. In this Silverlight application, add a Service Reference to the WCF List Data Service and name the namespace as ‘MyRef’.
Step 2: Right-Click on the Silverlight Project and from the properties, configure it to run in ‘Out-of-Browser’ mode with elevated rights as shown below:
Step 3: Design the MainPage.xaml by dragging and dropping a DataGrid, button and a TextBlock on it:
XAML

Step 4: Include the following reference:
using System.Data.Services.Client;
Step 5: Declare an object reference of the WCF Data Service Context as below:
MyRef.ProductsSiteDataContext objDataContext;
Step 6: In the loaded event write the following code:
The above URL represents the repository of the List WCF Data Service in the Product site collection. The DataContext (ProductSiteDataContext) class defines classes for all Lists defined in the SPS2010 web site collection.
Step 7: In the click event of the ‘Get Sales Info’ write the following code:
Pease read the comments carefully which explaines the behavior of the code.
Step 8: Run the application and the result will be as below:
Conclusion: The advantage of the WCF Data Service facility is that any client application can now make a call to the WCF services and interact with the SharePoint object model. It is not necessary for the end-user to directly log-in to the SharePoint Web Site application and work on it. WCF Data Services provided in SharePoint 2010 helps to implement integration based application with other client applications.
The entire source code of this article can be downloaded over here
This article has been editorially reviewed by Suprotim Agarwal.
C# and .NET have been around for a very long time, but their constant growth means there’s always more to learn.
We at DotNetCurry are very excited to announce The Absolutely Awesome Book on C# and .NET. This is a 500 pages concise technical eBook available in PDF, ePub (iPad), and Mobi (Kindle).
Organized around concepts, this Book aims to provide a concise, yet solid foundation in C# and .NET, covering C# 6.0, C# 7.0 and .NET Core, with chapters on the latest .NET Core 3.0, .NET Standard and C# 8.0 (final release) too. Use these concepts to deepen your existing knowledge of C# and .NET, to have a solid grasp of the latest in C# and .NET OR to crack your next .NET Interview.
Click here to Explore the Table of Contents or Download Sample Chapters!
Was this article worth reading? Share it with fellow developers too. Thanks!
Mahesh Sabnis is a DotNetCurry author and a Microsoft MVP having over two decades of experience in IT education and development. He is a Microsoft Certified Trainer (MCT) since 2005 and has conducted various Corporate Training programs for .NET Technologies (all versions), and Front-end technologies like Angular and React. Follow him on twitter @
maheshdotnet or connect with him on
LinkedIn