Part 8/11: Rapport with External Data Source – WCF RIA Service

Niladri.biswas
Posted by in LightSwitch category on for Beginner level | Points: 250 | Views : 10117 red flag

This is the eighth part of the 11 series LightSwitch tutorial. In this part we will learn about how to use WCF RIA Service as our external data source.

Table of Content

  1. Introduction
  2. Aim of the article
  3. Steps to use WCF RIA Service as the External DataSource
  4. Conclusion

Introduction

Rapid business application development is a need of today’s business and keeping that in focus software stewards wants to build the 3 tire applications at a lightning speed where there will be less code, less time will be spent on designing the UI screens , the BAL layer and DAL layer. By keeping all these into focus, on 26th July, 2011, Microsoft has released their new product – LightSwitch.

It is the simplest way for developers of all skill levels to develop business applications for the desktop as well as for cloud. This is the eighth part of the series of 12 LightSwitch tutorials where we will look into how to use WCF RIA service as the external datasource.

You can read the other parts of the LightSwitch tutorial as under

  1. Part 1: Introduction to Light Switch
  2. Part 2: Rapport with New Data Screen
  3. Part 3: Rapport with Search Data Screen
  4. Part 4: Rapport with Editable Grid Screen
  5. Part 5: Rapport with List and Details Screen
  6. Part 6: Rapport with Details Screen
  7. Part 7: Rapport with External Data Source – Database
  8. Part 8: Rapport with External Data Source – WCF RIA Service
  9. Part 9:Using a custom control in LightSwitch
  10. Part 10: Publish LightSwitch Application as Desktop application and host in local system
  11. Part 11: Publish LightSwitch Application as Web application

Assumption

The article assumes that, we have LightSwitch 2011 installed in our system

Steps to use WCF RIA Service as the External DataSource

Step 1: The first step in creating a LightSwitch application is to create a new project

Step 2: The Designer appears and the necessary folders for our project are added to the Solution Explorer. Close the designer

Step 3: The next step is to create a reusable WCF RIA Class Library. For that purpose, create a new Class library project

Step 4: Delete class1.cs file.Right Click->Add new item-> Ado.net Entity Data model

Step 5: Specify data source. Choose Player table

Step 6: Click Finish button.Build the project.Right Click->Add new item->Domain Service Class

Step 7: Click Add. The "Add New Domain Service Window" appears

We need the PlayerTable in the Domain Service Class. Also, un-check the "Enable client access" option as we donot need it.

Step 8: Click OK. The domain service class will be generated

namespace ClassLibrary1
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Data;
    using System.Linq;
    using System.ServiceModel.DomainServices.EntityFramework;
    using System.ServiceModel.DomainServices.Hosting;
    using System.ServiceModel.DomainServices.Server;


    // Implements application logic using the testEntities context.
    // TODO: Add your application logic to these methods or in additional methods.
    // TODO: Wire up authentication (Windows/ASP.NET Forms) and uncomment the following to disable anonymous access
    // Also consider adding roles to restrict access as appropriate.
    // [RequiresAuthentication]
    // TODO: add the EnableClientAccessAttribute to this class to expose this DomainService to clients.
    public class DomainService1 : LinqToEntitiesDomainService<testEntities>
    {

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'PlayerTables' query.
        
        public IQueryable<PlayerTable> GetPlayerTables()
        {
            return this.ObjectContext.PlayerTables;
        }
    }
}

Decorate the GetPlayerTables method with

[Query(IsDefault = true)] 

i.e.

Step 9: Now,choose the Appllication1 project(Light switch project) and click on "Add Data Source"

From the available Data source type, choose WCF RIA Service

Step 10 : Click On Next button

Step 11: Click Add Reference button.Choose Class Library1 project. This is our domain service.

Step 12: Click OK button and our domain service will be added to the "Available WCF RIA Service Classes" listbox

Step 13: Click Next and choose the entity

Step 14: Click Finish and we can find that our Domain Service has been added under the DataSources and the source table for our domain entity has also been added

Step 15: Now select File View

Step 16: Then click on "Show all files" option and all the files will be listed.Expand the ServerGenerated project and choose the Web.config file

Step 17: From the App.config of Class Library 1 project, copy the Connection string

And paste it to the web.config of ServerGenerated Project

And that's all. We are done.Now add a search screen and view the result

Conclusion

So in this part we have learn about how to use WCF RIA Service as our external data source.In the next article we will look into how to create custom control and use it in LightSwitch application.

Thanks for reading the article.Happy lightning with LightSwitch.

Page copy protected against web site content infringement by Copyscape

About the Author

Niladri.biswas
Full Name: Niladri Biswas
Member Level: Platinum
Member Status: Member
Member Since: 10/25/2010 11:04:24 AM
Country: India
Best Regards, Niladri Biswas
http://www.dotnetfunda.com
Technical Lead at HCL Technologies

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)