Page view counter

Tutorial: Data From a SQL DB via WCF (using LINQ)

My 4th tutorial Displaying SQL Database Data in a DataGrid using LINQ and WCF is now available, as is the source code and a version of the tutorial in PDF

For the moment, I recommend the PDF version as the images are clearer. We're fixing up the HTML versions of all the tutorials even as I write this.

LinqSQL

This tutorial walks through

  • Creating a LINQ query against your SQL Server database
  • Creating a WCF service to provide access to the results of your LINQ query
  • Binding Silverlight 2 controls against the WCF service

We will, over time have a way to provide direct feedback for each tutorial, but for now, please do send email or use the forums to ask questions about anything you read in the tutorials.

Thanks again,

 

-jese

Published Friday, April 04, 2008 9:37 AM by jesseliberty
Filed under:

Comments

# re: Tutorial: Data From a SQL DB via WCF (using LINQ)

I would like to see you add the update scenario to this. In my experience once the object get's disconnected from the DataContext updating the object becomes an issue. Or did you avoid the update strategically?

Friday, April 04, 2008 10:53 AM by SpoonStomper

# Silverlight Cream for April 4, 2008 -- #244

LeeOnTech blogs about a SL Modal Dialog, Scott Guthrie on Existing UI == UserControl, Chad Campbell has

Friday, April 04, 2008 5:02 PM by Community Blogs

# re: Tutorial: Data From a SQL DB via WCF (using LINQ)

Jesse, from the time that we call webService.GetCustomersByLastNameAsync(LastName.Text) until the "Completed" event is raised, there might be some time in real world application. And during this period, the user has no idea what's happening. Is there a way that we can always provide live feedback to user, what's going on from the time they clicked on the button until the grid gets filled?

Secondly, should we even bother with these techniques, if Astoria will be the "Official" data tier for SL?

So, how was your meeting with SL team?

..Ben

Friday, April 04, 2008 10:47 PM by BenHayat

# re: Tutorial: Data From a SQL DB via WCF (using LINQ)

Good tutorial by the way

Just to add to  BenHayat comments, should we be looking at SQL/LINQ ---> WCF ----> SL 2.0 as a way of building Data Driven RIA at all  or just wait for the complete story from ADO.Net Data Services team

What is the point of "Astoria"  if we have to code single methods for each data operation in WCF

Saturday, April 05, 2008 7:45 AM by tundei

# re: Tutorial: Data From a SQL DB via WCF (using LINQ)

Hi Tundei;

>>What is the point of "Astoria"  if we have to code single methods for each data operation in WCF<<

With Astoria, you tell it "What" you want in a declarative way rather than "How" you want, and it provides to you. Several years ago, I had to write my own middle tier data server and it gets very complicated, once it goes beyond a simple CURD, and what we see from some of these simple tutorials, are the tip of the iceberg, where the monster will get you in the details of transaction processing.

So, I give Astoria (ADO.Net Data Services) a real chance of implementing that tier, unless MS has another solution that's mainly for SL situations.

As of my last test, LINQ2SQL was not fully implemented in Astoria but Framework Entity was. But with beta 1 being out soon, we will see if LINQ2SQL will be officially supported for version 1.

So, let's see what Jesse has to say too!

..Ben

Saturday, April 05, 2008 9:23 AM by BenHayat

# re: Tutorial: Data From a SQL DB via WCF (using LINQ)

Saturday, April 05, 2008 9:27 AM by BenHayat

# re: Tutorial: Data From a SQL DB via WCF (using LINQ)

I get an exception when running the example.  It happens on this version and from the 15min video this is based on.  The only thing I did differently is use my own simple LINQ-To-SQL database.  Any suggestions?

Saturday, April 05, 2008 9:38 AM by shaggygi

# UpComingCamera.Info &raquo; Blog Archive &raquo; re: Tutorial: Data From a SQL DB via WCF (using LINQ)

Pingback from  UpComingCamera.Info  &raquo; Blog Archive   &raquo; re: Tutorial: Data From a SQL DB via WCF (using LINQ)

# re: Tutorial: Data From a SQL DB via WCF (using LINQ)

I ran into this error and thought I would share with whomever what needs to be done before you add the service reference:

type '***', provided as the Service attribute value in the ServiceHost directive could not be found.

I had to view the Service1.svc in the browser before I added the service reference to the Silverlight project.

Saturday, April 05, 2008 12:53 PM by Mortikhi

# re: Tutorial: Data From a SQL DB via WCF (using LINQ)

I forgot to add what exception was thrown while running the app. above.  It throws the followoing:

System.ServiceModel.CommunicationException in System.ServiceModel.dll

Is there something I missed?

Saturday, April 05, 2008 4:36 PM by shaggygi

# re: Tutorial: Data From a SQL DB via WCF (using LINQ)

Hi,

Nice tutorial.

I've a code similar to this sample, but I get an exception when calling the Async method. Visual Studio opens the file Reference.cs with the second line of the following method green colored.

public Desopedr.ServiceDesopedr.SilverlightLink[] EndGetSilverlightLinks(System.IAsyncResult result) {

               object[] _args = new object[0];

               Desopedr.ServiceDesopedr.SilverlightLink[] _result = ((Desopedr.ServiceDesopedr.SilverlightLink[])(base.EndInvoke("GetSilverlightLinks", _args, result)));

               return _result;

           }

An exception of type 'System.ServiceModel.ProtocolException' occurred in System.ServiceModel.dll but was not handled in user code

Additional information: [UnexpectedHttpResponseCode]

Arguments:Not Found

Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See go.microsoft.com/fwlink

If somebody has an idea of the problem... thx in advance

Saturday, April 05, 2008 9:05 PM by desopedr

# re: Tutorial: Data From a SQL DB via WCF (using LINQ)

I tested my WebService and it works when it is called by an ASP Web Application. What is wrong with Silverlight project ? (I changed binding to basicHttpBinding)

Thanks

Sunday, April 06, 2008 5:31 AM by desopedr

# re: Tutorial: Data From a SQL DB via WCF (using LINQ)

Thanks Ben,

I'm aware of home-grown solutions to this problem... I just wanted something easy out the box..:)..

Monday, April 07, 2008 9:12 AM by SpoonStomper

# Silverlight 2.0 leaps&amp;bounds ahead &laquo; Fluent.Interface

Pingback from  Silverlight 2.0 leaps&amp;bounds ahead &laquo; Fluent.Interface

Tuesday, April 22, 2008 6:21 AM by Silverlight 2.0 leaps&bounds ahead « Fluent.Interface

# re: Tutorial: Data From a SQL DB via WCF (using LINQ)

Thanks for the tutorial.

I created a similar webservice but i tried fetching data from two tables of a database.

here is the code

public List<Vg_Videocollectiontable> Getvideos()

       {

           Videogallery1DataContext db1 = new Videogallery1DataContext();

           var videolist = from v in db1.Vg_Videocollectiontables

                           select new  

                           {

                               v.Vg_Menubasenotable.Vg_Menuname,

                               v.Vg_Description,

                               v.Vg_Dwnlink,

                               v.Vg_Dwnname,

                               v.Vg_Presentedby,

                               v.Vg_Title,

                               v.Vg_Url

                           };

           return videolist.ToList();                          

       }

I get an error :

Error 1 Cannot implicitly convert type 'System.Collections.Generic.List<AnonymousType#1>' to 'System.Collections.Generic.List<Videogallery_Web.Vg_Videocollectiontable>'

Can someone help regarding the same.

Thankyou,

Regards,

Muthu

Wednesday, May 21, 2008 3:10 AM by muthu.fmass

# re: Tutorial: Data From a SQL DB via WCF (using LINQ)

Sometimes even after setting up binding="basicHttpBinding"

the service reference are not gettig created inside the silverlight project,

it gives the following error :

There was an error downloading 'localhost/Service1.svc'.

The request failed with the error message:

--

<HTML><HEAD><STYLE type="text/css">#content{ FONT-SIZE: 0.7em; PADDING-BOTTOM: 2em; MARGIN-LEFT: 30px}BODY{MARGIN-TOP: 0px; MARGIN-LEFT: 0px; COLOR: #000000; FONT-FAMILY: Verdana; BACKGROUND-COLOR: white}P{MARGIN-TOP: 0px; MARGIN-BOTTOM: 12px; COLOR: #000000; FONT-FAMILY: Verdana}PRE{BORDER-RIGHT: #f0f0e0 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #f0f0e0 1px solid; MARGIN-TOP: -5px; PADDING-LEFT: 5px; FONT-SIZE: 1.2em; PADDING-BOTTOM: 5px; BORDER-LEFT: #f0f0e0 1px solid; PADDING-TOP: 5px; BORDER-BOTTOM: #f0f0e0 1px solid; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e5e5cc}.heading1{MARGIN-TOP: 0px; PADDING-LEFT: 15px; FONT-WEIGHT: normal; FONT-SIZE: 26px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 3px; MARGIN-LEFT: -30px; WIDTH: 100%; COLOR: #ffffff; PADDING-TOP: 10px; FONT-FAMILY: Tahoma; BACKGROUND-COLOR: #003366}.intro{MARGIN-LEFT: -15px}</STYLE><TITLE>Service</TITLE></HEAD><BODY><DIV id="content"><P class="heading1">Service</P><BR/><P class="intro">The server was unable to process the request due to an internal error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.</P></DIV></BODY></HTML>

--.

Metadata contains a reference that cannot be resolved: 'localhost/Service1.svc'.

Content Type application/soap+xml; charset=utf-8 was not supported by service localhost/Service1.svc.  The client and service bindings may be mismatched.

The remote server returned an error: (415) Unsupported Media Type.

If the service is defined in the current solution, try building the solution and adding the service reference again.

If possible , i request you to helpregarding the same.

Only once i was able to create a service reference other times, even though everything is perfect, i am not to create a reference, i tried after building the application once/twice.

But couldn't able to succeed.

My mail id is muthu.fmass@gmail.com.

Please give me your response for both of my queries, if possible.

thanks a ton ,

Regards,

Muthaiah

Wednesday, May 21, 2008 5:31 AM by muthu.fmass

# re: Tutorial: Data From a SQL DB via WCF (using LINQ)

Hi I have a question,

how can I save new data entered by user from UserControl(textBox, confirm Button) via WCF web service? thanks for answer Ondrej

Monday, September 08, 2008 12:40 PM by OndrejKunc