Walkthrough: Using the Silverlight Business Application Template
[WCF RIA Services Version 1 Service Pack 2 is compatible with either .NET framework 4 or .NET Framework 4.5, and with either Silverlight 4 or Silverlight 5.]
In this walkthrough, you will learn how to create a WCF 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 RIA Services application, see the topics in the Authentication, Roles, and Profiles section.
Prerequisites
This and the other walkthroughs presented in the WCF RIA Services documentation require several prerequisite programs, such as Visual Studio 2010 and the Silverlight Developer Runtime and SDK, be installed and configured properly, in addition to WCF RIA Services and the WCF 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 WCF 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 RIA Services walkthroughs.
To create a solution
In Visual Studio 2010, select File, New, and then Project.
The New Project dialog box appears.
Select the Silverlight project type.
Select the Silverlight Business Application template and name the application ExampleBusinessApplication.
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.
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 RIA Services link exists between the client and server projects.
Build and run (F5) the application.
The home page of the application appears in your browser.
Click the login link.
The Login dialog box appears.
Click the Register now link.
The Register dialog box appears.
Add values to register a new user.
Click OK to create the new user.
Notice that you are now logged in as the user you registered.
Close the browser.
To use Windows Authentication
In the server project, open the Web.config file.
In the authentication element, set the mode property to Windows and remove the forms element.
<authentication mode="Windows"> </authentication>
In the client project, open the code-behind file (App.xaml.cs or App.xaml.vb) for the App.xaml file.
In the constructor, uncomment the line that sets the Authentication property to WindowsAuthentication and comment out the line that sets the property to FormsAuthentication.
Public Sub New() InitializeComponent() Dim webContext As New WebContext() 'webContext.Authentication = New FormsAuthentication() webContext.Authentication = New WindowsAuthentication() Me.ApplicationLifetimeObjects.Add(webContext) End Sub
public App() { InitializeComponent(); WebContext webContext = new WebContext(); //webContext.Authentication = new FormsAuthentication(); webContext.Authentication = new WindowsAuthentication(); this.ApplicationLifetimeObjects.Add(webContext); }
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
Walkthrough: Displaying Data in a Silverlight Business Application
Walkthrough: Displaying Related Data in a Silverlight Business Application