Telerik blogs

In my last blog we learned how to create an OpenAccess Domain Service that can be consumed by LightSwitch.  In this post we will continue down this path, and get the service loaded as a data source in a LightSwitch application.

Adding the Service

Our first task today is to add a LightSwitch Project to our solution. Do this through the standard “Add New Project” dialog.  You should see “LightSwitch” as one of the installed templates in the tree view on the left.  Select C#/VB, give the project a name, and click Ok.


Our solution explorer should now look like this:


Right click on “Data Sources” in the LightSwitch project, and select “Add Data Source”


Here you will be presented with a dialog allowing you to select an existing Database, SharePoint, or Ria Services as a data source.   Select Ria Service, and click Next.


Now we can choose the Ria Service we would like to use as a data source, LightSwitch provides implementations for AuthenticationServices, and SecurityServices out of the box, but we won’t mess with those right now. 

Click “Add Reference", and select the “YourNameSpace.Services.Web” Project from the reference list, and then click Ok.

SNAGHTML21e996c SNAGHTML22266c8 

Once the Ria Service loads into the “Choose a WCF Ria Service” listbox, select it, and click Next.


The next screen allows you to select which entities you would like to include, and you can name the data source.  Once you have done this click Finish.


If you are presented with a warning screen, click continue.  The warning reminds you to secure your service, and it will let you know that a few string[] properties could not be included.  This is fine, as they are not needed.


You should now see the new data source, listed under “Data Sources” in the Solution Explorer:


We have now successfully imported our OpenAccess Domain Service!  Lets do a build and see what happens…


DOH!  Not quite ready yet.  We still have a few more things to complete before the service is ready to use.  

LightSwitch Trickery

If you look at the compiler errors, you may notice that two of the errors are in a project named “ServerGenerated.”  This may be confusing at first because when you look in the Solution Explorer there isn’t a project with that name!  Behind the scenes LightSwitch created a number of projects for us, and they are not visible by default. To see these projects, select your LightSwitch application in the Solution Explorer, and change the current view from “Logical” to “File” in the top menu.


Now we can see all the projects LightSwitch created, and there is still not one named “ServerGenerated.”  Where is it?!  To access the “ServerGenerated” project,  click the “Show All Files” button at the top of the Solution Explorer, and viola!


Finishing up Configuration

Expand the “ServerGenerated” project node, and add references to:

     1. Telerik.OpenAccess.dll
     2. Telerik.OpenAccess.Ria.Extensions.dll
     3. Telerik.OpenAccess.35.Extensions.dll
     4. The project containing your model.  In my case: Demo.LightSwitchOA.Model 

Next, open the Web.Config in the “ServerGenerated” project, and the App.Config in your model project. Copy and paste the connection string from the App.Config, into the Web.Config.  

Build the solution, and it should complete with no errors.

The service is now ready to use!

Part 1

Part 2

Part 3


Comments are disabled in preview mode.