Try below code, it works perfectly fine:-
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using System.Linq;
using Microsoft.SharePoint.Linq;
using WCFService.ListWCFService;
namespace WCFService.WP_WCFService
{
public partial class WP_WCFServiceUserControl : UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected override void OnPreRender(EventArgs e)
{
try
{
System.Uri uri = new Uri("
http://localhost:16178/_vti_bin/ListData.svc");
SrgDataContext dc = new SrgDataContext(uri);
dc.Credentials = System.Net.CredentialCache.DefaultCredentials;
var query = from dev in dc.Announcements
select new
{
Title = dev.Title,
Body = dev.Body,
ExpiryDate = dev.Expires,
Path = dev.Path
};
gridAnnouncementList.DataSource = query;
gridAnnouncementList.DataBind();
//dc.Dispose();
}
catch (Exception ex)
{
throw ex;
}
}
protected void Button1_Click(object sender, EventArgs e)
{