What you want to see on DotNetFunda.com ?
Go to DotNetFunda.com
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 2251 |  Welcome, Guest!   Register  Login
Home > Articles > LightSwitch > Part 8/11: Rapport with External Data Source – WCF RIA Service

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

Article posted by Niladri.biswas on 9/9/2011 | Views: 4493 | Category: LightSwitch | Level: Beginner | Points: 250 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.

If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.

Page copy protected against web site content infringement by Copyscape
Found interesting? Add this to:



Please Sign In to vote for this post.

Experience:6 year(s)
Home page:http://www.dotnetfunda.com
Member since:Monday, October 25, 2010
Level:Diamond
Status: [Member]
Biography:Lead Engineer at HCL Technologies Ltd., having 6 years of experience in IT field.
I love to explore new technologies and love challenges and try to help others as much as possible not only by coding but also by all possible means.
>> Write Response - Respond to this post and get points
Related Posts

This is the sixth part of the 11 series LightSwitch tutorial. In this part we will learn about how to work with the Details screen for viewing the Master-Child records

This is the second part of the 11 series LightSwitch tutorial . In this part we will learn about how to work with the New Data Entry Screen for inserting records to the database in LightSwitch.

This is the tenth part of the 11 series LightSwitch tutorial. In this part we will learn about how to Publish LightSwitch Application as Desktop Application

This is the ninth part of the 11 series LightSwitch tutorial. In this part we will learn about how to use custom control in LightSwitch Application

This is the third part of the 11 series LightSwitch tutorial. In this part we will learn about how to work with the Search Data Screen for searching the record that has been entered from the New Data Screen in LightSwitch.

More ...
About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/21/2013 1:57:55 PM