Reader Level:

Select List Data With WCF Service in SharePoint 2010 Programmatically Using VS 2012

Posted by Vijay Prativadi Articles | SharePoint September 14, 2012
Today, in this article let’s play around with one of the interesting and most useful concepts in SharePoint 2010.
  • 0
  • 0
  • 4202


Today, in this article let's play around with one of the interesting and most useful concepts in SharePoint 2010.

Question: What is select list data with wcf service?

In simple terms "It enables to select data from SharePoint custom list using a client side environment via WCF service".

Step 1: Open SharePoint 2010 Central Administration and navigate to a specific site.

Step 2: Open up Visual Studio 2012 and create an "ASP.NET Web Forms Application", as in:


Step 3: Remove the following reference for the project:




Step 4: Replace with a new reference for the project. (For this you need to install ADO.NET Data Services.exe file from here.)


After installation, browse to the specific location at:


C:\Program Files (x86)\ADO.NET Data Services V1.5 CTP2\bin


Add this reference to the project: Microsoft.Data.Services.Client.dll


Step 5: Add the service reference to the project. This should come up from the following link. (So here the site URL is http://win-5c3g1lanj3k:29782/ . This might be differerent based on your custom site URL. Another part is _vti_bin/ListData.svc that should be common to access the service reference for any site.)




Step 6: The complete code of WebForm1.aspx looks like this:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="SelectListDataWCFDataServiceApp._Default" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">

<head id="Head1" runat="server">




    <form id="form1" runat="server">





                    <td colspan="2">

                        <asp:Label ID="Label1" runat="server" Text="Select List Data - WCF Data  in SharePoint 2010 using VS 2012 "

                            Font-Bold="true" Font-Size="Large" Font-Names="Verdana" ForeColor="Maroon"></asp:Label>




                    <td colspan="2" align="center">

                        <asp:Button ID="Button2" runat="server" Text="Select List Data" Font-Names="Verdana"

                            Width="166px" BackColor="Orange" Font-Bold="True" OnClick="Button2_Click" /><br />

                        <br />




                    <td colspan="2" align="center">

                        <asp:GridView ID="GridView1" runat="server" BackColor="LightGoldenrodYellow" BorderColor="Tan"

                            BorderWidth="1px" CellPadding="2" EnableModelValidation="True" ForeColor="Black"

                            GridLines="None" AutoGenerateColumns="False">

                            <AlternatingRowStyle BackColor="PaleGoldenrod"></AlternatingRowStyle>

                            <FooterStyle BackColor="Tan"></FooterStyle>

                            <HeaderStyle BackColor="Tan" Font-Bold="True"></HeaderStyle>

                            <PagerStyle HorizontalAlign="Center" BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue">


                            <SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite"></SelectedRowStyle>


                                <asp:BoundField DataField="ID" HeaderText="Student Id" ReadOnly="true" SortExpression="Id" />

                                <asp:BoundField DataField="FirstName" HeaderText="First Name" ReadOnly="true" />

                                <asp:BoundField DataField="LastName" HeaderText="Last Name" ReadOnly="true" />

                                <asp:BoundField DataField="Age" HeaderText="Age" ReadOnly="true" />






                    <td colspan="2" align="center">

                        <asp:Label ID="Label5" runat="server" Font-Bold="true" Font-Names="Verdana" ForeColor="Maroon"></asp:Label>










Step 7: The complete code of WebForm1.aspx.cs looks like this:


using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using SelectListDataWCFDataServiceApp.ServiceReference1;

namespace SelectListDataWCFDataServiceApp


    public partial class _Default : System.Web.UI.Page


        protected void Page_Load(object sender, EventArgs e)



        protected void Button2_Click(object sender, EventArgs e)


            MainSiteDataContext objContext = new MainSiteDataContext(new Uri("http://win-5c3g1lanj3k:29782/_vti_bin/ListData.svc"));

            objContext.Credentials = System.Net.CredentialCache.DefaultCredentials;

            GridView1.DataSource = objContext.Students.ToList();






Step 8: The output of the application looks like this:



Step 9: The select data output of the application looks like this:



I hope this article is useful for you.


Trending up