Walkthrough: Using the Silverlight Business Application Template
[ This document was written for WCF Services Version 1 Service Pack 2 and might not be up to date Please see Release Notes or Changelog for a list of changes since WCF RIA Services ]
In this walkthrough, you will learn how to create a Open Ria Services solution by using the Silverlight Business Application template. This walkthrough shows how to create the application and how to use several of the features that are made available by the template with very little additional work. It also shows how to switch from the default authentication mode of Forms Authentication to Windows Authentication.
The Silverlight Business Application template creates a project that automatically includes many features that you typically want in a business application, such as controls to log in users and to register new users. The project created by the template is also set up to use Silverlight navigation, which means you can easily add new Silverlight pages for additional functionality.
By default, the Silverlight Business Application template enables authentication, roles, and profiles. The default authentication mode used by the template is Forms Authentication, but you can change the authentication mode to Windows Authentication by simply changing two configuration values. The procedure for making this change is provided here.
For more information about how to use the services for authentication, roles, and profiles supported in a Open Ria Services application, see the topics in the Authentication, Roles, and Profiles section.

Prerequisites

This and the other walkthroughs presented in the Open Ria Services documentation require several prerequisite programs, such as Visual Studio and the Silverlight Developer Runtime and SDK, be installed and configured properly, in addition to Open Ria Services and the Open Ria Services Toolkit. They also require installing and configuring SQL Server 2008 R2 Express with Advanced Services and installing the AdventureWorks OLTP and LT database.
Detailed instructions for the satisfaction of each of these prerequisites are provided by the topics within the Prerequisites for Open Ria Services node. Follow the instructions provided there before proceeding with this walkthrough to ensure that you encounter as few problems as possible when working through this Open Ria Services walkthroughs.

To create a solution

  1. 1.
    In Visual Studio, select File, New, and then Project.
    The New Project dialog box appears.
  2. 2.
    Select the Silverlight project type.
  3. 3.
    Select the Silverlight Business Application template and name the application ExampleBusinessApplication.
    ​
    ​
  4. 4.
    Click OK.
    Notice the project structure that is created. The Silverlight client project includes Silverlight pages in the Views folder. These pages enable logging in users and registering new users.
  5. 5.
    In Solution Explorer, right-click the Silverlight client project and select Properties.
    The Silverlight tab of the project designer appears. At the bottom of the tab, notice that a Open Ria Services link exists between the client and server projects.
  6. 6.
    Build and run (F5) the application.
    The home page of the application appears in your browser.
    ​
    ​
  7. 7.
    Click the login link.
    The Login dialog box appears.
    ​
    ​
  8. 8.
    Click the Register now link.
    The Register dialog box appears.
    ​
    ​
  9. 9.
    Add values to register a new user.
    ​
    ​
  10. 10.
    Click OK to create the new user.
    Notice that you are now logged in as the user you registered.
  11. 11.
    Close the browser.

To use Windows Authentication

  1. 1.
    In the server project, open the Web.config file.
  2. 2.
    In the authentication element, set the mode property to Windows and remove the forms element.
  3. 3.
    In the client project, open the code-behind file (App.xaml.cs or App.xaml.vb) for the App.xaml file.
  4. 4.
    In the constructor, uncomment the line that sets the Authentication property to WindowsAuthentication and comment out the line that sets the property to FormsAuthentication.
    1
    Public Sub New()
    2
    InitializeComponent()
    3
    ​
    4
    Dim webContext As New WebContext()
    5
    'webContext.Authentication = New FormsAuthentication()
    6
    webContext.Authentication = New WindowsAuthentication()
    7
    Me.ApplicationLifetimeObjects.Add(webContext)
    8
    End Sub
    Copied!
    1
    public App()
    2
    {
    3
    InitializeComponent();
    4
    ​
    5
    WebContext webContext = new WebContext();
    6
    //webContext.Authentication = new FormsAuthentication();
    7
    webContext.Authentication = new WindowsAuthentication();
    8
    this.ApplicationLifetimeObjects.Add(webContext);
    9
    }
    Copied!
  5. 5.
    Build and run (F5) the application.
    Notice that you are now logged in with your Windows account. The Silverlight Business Application includes code in the Application_Startup method that attempts to load the user for Windows Authentication.

See Also

Tasks

Last modified 6mo ago