Showing posts with label Silverlight. Show all posts
Showing posts with label Silverlight. Show all posts

Saturday, May 26, 2012

Silverlight interview


What is Microsoft Silverlight?

1)Silverlight is a web based technology, launched by Microsoft in April 2007.
Silverlight is considered as a competitor to Adobe's Flash.
2)Silverlight is Microsoft's implementation of a cross-browser, cross-platform client framework that allows designers
and developers to deliver Rich Internet Applications (RIA) embedded in Web pages.
3)It supports advanced data integration, multithreading, HD video using IIS Smooth Streaming, and built-in content protection.
Silverlight enables online and offline applications for a broad range of business and consumer scenarios.
4)One of the design goals of the Silverlight technology is to fill the gap between Windows applications
 and Web applications in terms of creating Graphical User Interfaces (GUI).

Why use Silverlight?

1)It is a cross-browser, cross-platform technology which provides a consistent user experience everywhere it runs.
2)Better development tools -Visual Studio 2010, Expression Blend.
3)It runs a client-side application that can read data and update the UI without interrupting the user by refreshing
 the whole page.
4)It can run asynchronous communications with the server, allowing the UI to continue to function while waiting
 for the server response.It delivers rich video, audio, and graphics.

Which programming language can be used to write the backend of the Silverlight application?

We can either use Visual C# or Visual Basic to code the backend of the silverlight application.
Here backend means the code behind files for the Sivlerlight pages.

Stack Panel
use this for grouping controls in a stack (horizontal/vertical). Controls do not overlapped.

Grid Panel
most flexible, multi row/columns layouts. Similar to a HTML table

What are the goals of Moonlight?

1)To run Silverlight applications on Linux.
2)To provide a Linux SDK to build Silverlight applications.
3)To reuse the Silverlight engine built for desktop applications.


What is the Silverlight plug-in?

1)The Silverlight plug-in is a very lightweight component that is necessary for users to access Silverlight applications.
2)The Silverlight plug-in is responsible for accessing the Silverlight object in the Web page,
 downloading and accessing the XAP package, setting up the program environment, and beginning execution of the application.

What is Silverlight Runtime?

Silverlight Runtime is a browser plug-in to support Silverlight enabled applications.
If the Silverlight runtime is not installed, browsers will not be able to run Silverlight elements in the browser.

What is Silverlight SDK?

Silverlight SDK is a set of tools, documentation, samples, and templates for web developers to enable them to easily develop
Silverlight enabled applications.SDK is not really mandatory to develop Silverlight applications

What are the tools required to develop Silverlight applications?

1)Silverlight runtime:To run Silverlight applications in a web browser, you need to have the Silverlight runtime installed
on the client browser as a plug-in.
2)Silverlight SDK: This includes a set of tools required to compile and build Silverlight controls.
If you are comfortable writing HTML using Notepad and compiling .NET applications from console tools,
 then you just need the Silverlight SDK to develop Silverlight applications.
3)Microsoft Expression Studio - This tool is meant for web designers to create rich visual elements for
Silverlight applications.
4) Expression Studio is recommended for web designers who create rich internet applications with enhanced
visual content and graphics. There are several features provided for creating enhanced graphics elements,
 with lot of options to pick color, font, etc.
5)Download Silverlight Toolkit - This toolkit is a Microsoft project containing Silverlight controls, components,
and utilities that can be downloaded and used in your Silverlight applications. It includes full source code, samples,
 and tests.
6)Download .NET RIA Services - Microsoft .NET RIA Services simplifies the traditional n-tier application pattern
by bringing together the ASP.NET and Silverlight platforms. RIA Services provides a pattern to write application logic
 that runs on the mid-tier and controls access to data for queries, changes, and custom operations.

Which tool to use - Expression Studio or Visual Studio?

If your Silverlight application includes just graphics and visual elements, then you can use Expression Studio.
 However, if you are a programmer and if your Silverlight application includes programming logic,
 then you might want to choose Visual Studio.

What is a .xap file?

.xap file is a Silverlight-based application package (.xap) that is generated when the Silverlight project is built.
A .xap file is the compressed output file for a Silverlight application. The .xap file includes AppManifest.xaml,
 the compiled output assembly of the Silverlight project (.dll), and the resource files referred to by the
Silverlight application

What is a Silverlight.js file? 

Silverlight.js is a helper file which enables websites to create advanced Silverlight installation and instantiation
experiences.
 You can call the createObject and createObjectEx functions defined in this file to embed the Silverlight plug-in in
a web page.

What is the use of the ClientBin folder? 

The ClientBin folder is used to place the .xap file of a Silverlight application.
You can keep it anywhere in your web application, but this is the default location used by Silverlight.


How to change the default page of a Silverlight application? 

To change the default page of a Silverlight application, you need to set the RootVisual property
inside the Application_Startup event of the App.xaml file.
Collapse private void Application_Startup(object sender, StartupEventArgs e) { this.RootVisual = new MainPage(); }

What is XAML? 

1)XAML stands for eXtensible Application Markup Language, and is a declarative markup language that follows
the XML rule and is used for developing User Interfaces in WPF and Silverlight technology.

What is the AppManifest.xml file? 

First, let’s look at an example AppManifest.xaml file: Collapse The first element in AppManifest.xaml
is a Deployment node. This node defines the application, and contains the child AssemblyPart nodes.
As you can see the AssemblyPart nodes define what assemblies (DLLs) are contained within the .xap file,
and give each of them a name.

 What files are contained within the .xap file? 

The .xap file contains an application manifest (AppManifest.xaml) file and all the necessary DLLs that are
required by the application. The first DLL contained is the compiled version of your application and
 has the same name of your application. In my test, I created an application named "SilverlightApplication1",
so the DLL is named "SilverlightApplication1.dll". The rest of the DLLs are the dependencies the application requires.

What is app.xaml? 

1)App.xaml is a file used by Silverlight applications to declare shared resources like brushes, various style objects,
templates etc. Also, the code-behind file of app.xaml.cs is used to handle global application level events
like Application_Startup, Application_Exit, and Application_UnhandledException (similar to the Global.asax file
for ASP.NET applications).
2)This file used to set silverlight application start up page.

What is the Silverlight official name? 

Silverlight was formerly code-named "WPF/E".

What are the main features and benefits of Silverlight? 

1)Compelling cross-platform user experiences.
2)Flexible programming model with collaboration tools.
3)High-quality media, low-cost delivery.
4)Connected to data, servers, and services.

What is MainPage.xaml? 

When you create a Silverlight project using Visual Studio, it creates a default XAML file called "MainPage.xaml".

Which language is Silverlight developed in? 

It was developed using a combination of C# and C++.

What is the difference between WPF and Silverlight?

1)WPF will be used in the development of Rich Windows Graphical User Interfaces (GUI) for Windows client users.
2)Silverlight for developing rich browser based internet applications.
3)WPF is Microsoft’s latest development platform for building next-generation Windows client applications.
4)Silverlight is Microsoft’s latest development platform for building next-generation Web client applications.
5)WPF runs windows only.
6)Silverlight Cross OS, cross browser, cross device.

What is the difference between Silverlight and ASP.NET AJAX?

What are the different Layout controls available in Silverlight?
There are three different types of Layout controls provided by Silverlight:
1)Canvas - Position child elements absolutely in x, y space.
2)StackPanel - Position child elements relative to one another in horizontal or vertical stacks.
3)Grid - Position child elements in rows and columns. You have to add a layout panel to every XAML page you create.
All other UI elements must be added inside one of the layout panels. Each page can have exactly one layout panel control.

What is meant by RIA? 

RIA stands for Rich Internet Applications, which are Web applications with rich user interfaces including
media elements such as audio, video etc. You can think of them as being similar to powerful and rich desktop applications,
 except that RIA applications are Web based.

What is .NET RIA Services? 

Microsoft .NET RIA Services helps to simplify the n-tier application pattern by combining the ASP.NET and
Silverlight platforms. RIA Services provides a pattern using which you can write application logic that can run on
the mid-tier and controls access to data for queries, changes, and custom operations.
It also provides support for data validation, authentication, and roles by integrating with Silverlight components
on the client and ASP.NET on the middle tier.

What is the relationship and difference between Silverlight and ASP.NET?


1)Silverlight runs completely on the client, while ASP.NET mainly runs on the server, but also has a few parts running on the client.
2)Silverlight can’t work with a database directly; instead, it consumes data from Web Services, while ASP.NET has strong support for working with databases directly.


MVVM Architecture‏?

The Model-View-View Model (MVVM) pattern provides a flexible way to build Silverlight applications that promotes code re-use, simplifies maintenance and supports testing. The pattern consists of three different components including the Model (entities and code on the server), the View (the Silverlight screens) and the ViewModel (the glue between the Model and the View.


existing Silverlight application that uses code-behind files for all of the C# or VB code into a more structured architecture that follows the MVVM pattern. Topics covered include creating a service agent class to handle calls to a WCF service, creating a ViewModelBase class, creating a custom ViewModel class and binding a ViewModel to a View declaratively in XAML. You'll also see how commanding can be used to wire-up events in a View to methods in a ViewModel. 


N-Tier Architecture?

If you develop complex business applications with a large codebase that can easily adapt to changing environments you introduce multiple tiers or layers. For example, you create a Data Access Layer that communicates with your data source whatever that is and passes the requested data to the layer above in object oriented form. 
You don’t have ADO.NET libraries in Silverlight so you can’t interact with a database directly (and you shouldn’t do that anyway). So here is what you should have (at least): 
  1. Your Silverlight Application - Presentation layer
  2. A WCF Service – Service Layer
  3. Your Database / additional ADO.NET logic to interact with your database – Persistence Layer

Thursday, May 10, 2012

Silverlight 4.0 and MVVM Pattern

What is MVVM Pattern?


MVVM (Model-View-View Model) is the  design Pattern code model used for WPF/Silverlight UI. MVVM is the guideline a developer should follows in order to achieve a more testable, debug gable, manageable, readable Application.

MVVM is implemented with zero code behind.  Yes, no button click event hander in the code behind file, no form/windows load logic, no UI binding logic, and no UI validation or type casting code in the code behind file. Yes, I mean absolutely no code or logic in the UI mainpage.xaml.cs file.

The reason we don't want to put code-behind in our project is so that one can write a unit test against the code and create instances and run methods on our instances in a unit test.

The following features are used in order to achieve the MVVM pattern with no logic on the UI code behind file and to make sure that the presentation layer and logic remain loosely couple.
  1. Using the strong two-way binding capability of the WPF/Silverlight UI (through XAML)
  2. Implementing an IValueConvert for binding (eg: string converted to a Color instance, and also avoid type casting)
  3. Use INotification in our model or Dependency Property
  4. Set the data context at the xaml level
  5. Set Static resources at the xaml level
  6. ICommand for avoiding the code behind event handler.
  7. Use of validation=true in xaml(presentation layer)
Before MVVM, the MVP pattern was famous for its use in WinForm and WPF applications (it never took full advantage of the two-way binding feature of WPF).  The MVC pattern is still well-known for its use with Asp.net Application.

Below are some drawbacks of the old fashion WinForm or WPF/Silverlight applications that didn't leverage the power of the mvvm pattern.
  1. The presentation and the code behind logic is tightly coupled
  2. If we change the UI control we are forced to change the logic in the code behind
  3. It makes it hard to imagine a way of having more than one view sharing the same logic.
  4. It's not possible to write a unit test for a view that uses code behind because the presentation layer is tightly couple to the control.
  5. In previous practice with the WPF application, the view (xaml) often acted as a data store.
Advantages of MVVM pattern
  1. Proper layering of the view and the data. The data is not stored in the view, The view is just for presenting the data.
  2. Clean testable and manageable code.
  3. No code behind so the presentation layer and the logic is loosely coupled.
  4. With Silverlight 4.0 we have new ICommand Support (this was previously only present in the PRISM framework

Monday, May 7, 2012

What are the new features of Silverlight 4

  • Support for Google's Chrome browser.
  • Web cam and microphone support.
  • Printing support.
  • Full keyboard access while running in full-screen mode.
  • Programmatic access to a user's local document folder.
  • Improved mouse support, including right button support and mouse wheel support.
  • Elevated trust and support for local Component Object Model (COM) objects.
  • New notification support to display messages to end users.
  • New and enhanced controls such as a RichTextBox and an enhanced DataGrid control.
  • New support for implicit theming of controls.
  • New hosted browser support for rendering HTML inside Silverlight.
  • WCF data layer enhancements.
  • Localization enhancements with bi-directional text.
  • Support for Managed Extensibility Framework.
  • Enhanced data binding support.
  • Enhanced animation effects.
  • Clipboard and drag and drop support.
  • Deep Zoom performance enhancements.
  • WCF Rich Internet Application (RIA) Services.
  • Content protection for H.264, and support for playing offline DRM protected media.

Silverlight5 Features

Improved media support
  • ·        Low Latency Audio Playback: Use the SoundEffect API to trigger low-latency sound
  • ·        Variable Speed Playback: allows video to be played at different speeds and supports fast-forward and rewind. At up to twice the speed, audio pitch correction allows users to watch videos while preserving a normal audio pitch.
  • ·        H/W Decode of H.264 media: Significant performance improvements with H.264 media decoding of unprotected content
  • ·        DRM Key Rotation/LiveTV Playback: Long-running live TV playback protected through the use of rotating licenses
  • ·        Application-Restricted Media: Prevents playback of protected content in unauthorized applications

Improved Text support
  • Text Tracking & Leading: Exercise fine-grained control over the spacing between characters and lines in your text
  • Linked Text Containers: Create linked RichTextBlocks that allow text to flow seamlessly from one to the next
  • OpenType and Pixel Snapped Text : Improved text clarity
  • Postscript vector printing: reduces the size of print jobs and improves rendering quality of text
  • Performance improvements for Block Layout Engine.

Building next-generation business applications
  • PivotViewer -- now included in SDK. Adds support for dynamic client-based collections, XAML-based visuals, and customizability.
  • ClickCount: Add support for multi-click to your application
  • Listbox/ComboBox type-ahead text searching: Listboxes and ComboBoxes can now scroll based on text input
  • Ancestor RelativeSource Binding: Bind to a property on a parent control
  • Implicit DataTemplates: Allow DataTemplates to be defined implicitly
  • DataContextChanged event
  • Added PropertyChanged to the UpdateSourceTrigger enum
  • Save File and Open File Dialog: Specify a default filename when you launch your SaveFileDialog and specify a default directory when you launch your OpenFileDialog
  • Databinding Debugging: Set a breakpoint directly in XAML, examine locals, and debug your bindings
  • Custom Markup Extensions: Execute custom code at XAML parse time
  • Binding on Style Setters: You can now specify a binding within a style

Silverlight 5 performance improvements
  • Parser Performance Improvements: Improved XAML parse times for UserControls & ResourceDictionaries
  • Network Latency Improvements: Significant performance improvement in ClientHttpWebRequest scenarios
  • H/W accelerated rendering in IE9 windowless mode: Silverlight now uses the new SurfacePresenter APIs for H/W accelerated rendering in IE9 windowless mode
  • Multicore JIT: Shortens the start-up time for Silverlight apps
  • 64-bit browser support

Graphics improvements
  • Improved Graphics stack: The graphics stack has been re-architected to add features such as Independent Animations
  • 3D: Use the XNA API on the Windows platform to gain low-level access to the GPU and draw vertex shaders and low-level 3D primitives. Includes Render targets, XNA built-in effects, surface composition settings for depth/stencil buffers and multi-sample anti-aliasing

Silverlight 5 extends features of the "Trusted Application" model
Silverlight 5 extends features of the ‘Trusted Application’ model to the browser for the first time. These features, when enabled via a group policy registry key and an application certificate, mean users won’t need to leave the browser to perform complex tasks:
  • Multiple window support: Launch multiple top-level windows inside a SL OOB application
  • Full-Trust in-browser: Using Group Policy, deploy signed in-browser applications that harness the full power of full-trust functionality
  • In-browser HTML support: Host your WebOC within an in-browser SL application
  • Unrestricted File System Access: Read from and write to any directory on your system, from a full-trust application
  • P/Invoke support : Allows existing native code to be run directly from Silverlight

Tools improvements
  • Visual Studio Team Test support.

How many types of binding in silverlight

Databinding is the process of establishing a connection between a source and target. In Silverlight databinding, the source is the CRL object and the target is Silverlight controls (XAML Elements). Let me show you a visual.

Binding Modes

There are three types of data binding that happens in Silverlight applications between a source and target.
  1. OneTime data binding
  2. OneWay data binding (default mode)
  3. TwoWay data binding
OneTime data binding: As the name suggests, data binding happens between the source and target only once. In this binding, the source (CRL object) data will bind with the target (XAML element) only when the page executes the first time. Later on, any changes made in the source will not be reflected back in the target element. You will prefer to use this binding mode to reduce overhead if you know that the source property won’t change.
OneWay data binding: In this data binding, the source will immediately inform about changes to the target control. We will be using this binding only for frequently changed elements. This is the default mode.
TwoWay data binding: This happens in bidirectional mode. Whenever any change occurs in the backend or the CRL object, it will inform to the XAML controls immediately, and vice versa.

Friday, April 27, 2012

Wcf Ria Service using in silverlight Application

Steps for creating such an application are below.
Create New Silverlight Application

New project >> Select Silverlight Application.



Check "Enable WCF RIA Services" check box










Create Entity Data model.







Select tables, views and stored procedure from given list to add it to the entity data model.



Create Domain Service.

Before adding a new domain service, compile the web project.


Map or enable entity(s) with domain service. In the Entities list you get all tables (also called entities) available in the entity model.

  
Now build both projects; Silverlight as well as web. After compiling you will have auto generated code in the Silverlight project which is responsible for communication between Silverlight and Domain service.



Domain service has many built-in methods for selecting, inserting, updating and deleting the entity(s). You may also add new methods as per your requirement.
In the attached Silverlight project we a create custom method to get customer from its id.

public CustomerMaster GetCustomerFromId(int customerId)
{
    return this.ObjectContext.CustomerMasters.Where(d => d.CustomerId == customerId).FirstOrDefault();
}

After completion of the web project, you may access this method in Silverlight project.

Binding Data using WCF service in silver light 4

Using simple LINQ query and LINQ to sql class.
Open Project in visual studio 2010.
Right click on <Projects>.web Project and select
add new item
select linq to sql classes.Name as Exercise.
Select your database, tables, stored procedures if required.
Right click on <Projects>.web Project and select
add new item
select silverlight Tab and select silverlight enabled wcf service.Name as WCFexample.
Add the following code to get data from table


[OperationContract]
        List<nvmsl_ClientUser> GetUsers()
        {
            //Creating object for Exercise.dbml.cs class's ExerciseDataContext
            ExerciseDataContext dc = new ExerciseDataContext();

            var users = from user in dc.nvmsl_ClientUsers select user;
            return users.ToList();

        }
Test the webservice:
To test the web service, reight click on service and select view in browser.
Copy the link.
Open visual studio 2010 command prompt from visual studio 2010 tools.
Type wcftestclient and enter.
One window will open, right click on My Project services from the right side of the window.
Select add service
Paste the link and click add.
Select the required function and select invoke.
Testing completed successfully.

Adding service reference.
Right click on <project> select add service reference.
Select discover.
Select required service and add namespace.

Add a silver light page

-> And add datagrid control name it as userdatagrid, ser Autogenerated column property = True.
->And add the following code in page to bind data to userdatagrid.

public <Pageconstructor>()
        {
            InitializeComponent();

            WCFexampleService.WCFexampleClient ws = new WCFexampleService.WCFexampleClient();
            ws.GetUsersCompleted += new EventHandler<WCFexampleService.GetUsersCompletedEventArgs>(ws_GetUsersCompleted);
            ws.GetUsersAsync();
        }

        void ws_GetUsersCompleted(object sender, WCFexampleService.GetUsersCompletedEventArgs e)
        {
            UserdataGrid.ItemsSource = e.Result;
        }


Run the application.


Using ADO.Net Entity Data Model, simple LINQ Query.
Open Project in visual studio 2010.
Right click on <Projects>.web Project and select
add new item
select ADO.net Entity Data Model.Named WCFexampleModel. Give the connection Details and name it as NitsWebSLEntities.
Select required tables and procedures.
Build.



 Right click on <Projects>.web Project and select
add new item
select silverlight Tab and select silverlight enabled wcf service.Name as WCFexample.
Add the following code to get data from table


[OperationContract]
        List<nvmsl_ClientUsers> GetUsers()
        {

NitsWebSLEntities dc = new NitsWebSLEntities();
            var users = from user in dc.nvmsl_ClientUsers select user;
            return users.ToList();

        }
Test the webservice:
To test the web service, reight click on service and select view in browser.
Copy the link.
Open visual studio 2010 command prompt from visual studio 2010 tools.
Type wcftestclient and enter.
One window will open, right click on My Project services from the right side of the window.
Select add service
Paste the link and click add.
Select the required function and select invoke.
Testing completed successfully.

Adding service reference.
Right click on <project> select add service reference.
Select discover.
Select required service and add namespace.

Add a silver light page

-> And add datagrid control name it as userdatagrid, ser Autogenerated column property = True.
->And add the following code in page to bind data to userdatagrid.

public <Pageconstructor>()
        {
            InitializeComponent();

            WCFexampleService.WCFexampleClient ws = new WCFexampleService.WCFexampleClient();
            ws.GetUsersCompleted += new EventHandler<WCFexampleService.GetUsersCompletedEventArgs>(ws_GetUsersCompleted);
            ws.GetUsersAsync();
        }

        void ws_GetUsersCompleted(object sender, WCFexampleService.GetUsersCompletedEventArgs e)
        {
            UserdataGrid.ItemsSource = e.Result;
        }





Using ADO.Net Entity Data Model, Stored procedure.( Returns a collection of : Entities.)
Open Project in visual studio 2010.
Right click on <Projects>.web Project and select
add new item
select ADO.net Entity Data Model.Named WCFexampleModel. Give the connection Details and name it as NitsWebSLEntities.
Select required tables and procedures.
Build.
Create a stored procedure named Tnvmsl_GetClientUsers.
CREATE PROCEDURE [dbo].[Tnvmsl_GetClientUsers]
AS
BEGIN
select * from dbo.nvmsl_ClientUsers
    END

Right click on WCFexampleModel.edmx select model browser.
 From the left corner Tree view select Tnvmsl_GetClientUsers Procedure in stored procedures in NitsWebSLModel.Store.
Right click on Tnvmsl_GetClientUsersselect Add function Import.
Select Returns a collection of : Entities.


Add the following code in the service
    [OperationContract]
        List<nvmsl_ClientUsers> Get_ClientUsers()
        {
            NitsWebSLEntities dc = new NitsWebSLEntities();
            return dc.Tnvmsl_GetClientUsers().ToList();
        }

Add the following code in Silverlight page.

WCFexampleService.WCFexampleClient ws = new WCFexampleService.WCFexampleClient();
            ws.Get_ClientUsersCompleted += new EventHandler<WCFexampleService.Get_ClientUsersCompletedEventArgs>(ws_Get_ClientUsersCompleted);
            ws.Get_ClientUsersAsync();


        void ws_Get_ClientUsersCompleted(object sender, WCFexampleService.Get_ClientUsersCompletedEventArgs e)
        {
            UserdataGrid.ItemsSource = e.Result;
        }






Using ADO.Net Entity Data Model, Stored procedure.( Returns a collection of : Scalars.)

Open Project in visual studio 2010.
Right click on <Projects>.web Project and select
add new item
select ADO.net Entity Data Model.Named WCFexampleModel. Give the connection Details and name it as NitsWebSLEntities.
Select required tables and procedures.
Build.
Create a stored procedure named Tnvmsl_GetUserName.
ALTER PROCEDURE [dbo].[Tnvmsl_GetUserName]
(@UserId int)
AS
BEGIN
select UserName from dbo.nvmsl_ClientUsers where UserId=@UserId
END

Right click on WCFexampleModel.edmx select model browser.
 From the left corner Tree view select Tnvmsl_GetUserName Procedure in stored procedures in NitsWebSLModel.Store.
Right click on Tnvmsl_GetUserName Add function Import.
Select Returns a collection of : Scalars

Add the following code in the service
  [OperationContract]
        List<string> Get_UserNameByUserID(int id)
        {
            NitsWebSLEntities dc = new NitsWebSLEntities();
            return dc.Tnvmsl_GetUserName(id).ToList();

        }


Add the following code in Silverlight page.
WCFexampleService.WCFexampleClient ws = new WCFexampleService.WCFexampleClient();
            ws.Get_UserNameByUserIDCompleted += new EventHandler<WCFexampleService.Get_UserNameByUserIDCompletedEventArgs>(ws_Get_UserNameByUserIDCompleted);
            ws.Get_UserNameByUserIDAsync(1);

void ws_GetUsersCompleted(object sender, WCFexampleService.GetUsersCompletedEventArgs e)
        {
            UserdataGrid.ItemsSource = e.Result;
        }


Using ADO.Net Entity Data Model, Stored procedure.( Returns a collection of : Complex Types.)
Open Project in visual studio 2010.
Right click on <Projects>.web Project and select
add new item
select ADO.net Entity Data Model.Named WCFexampleModel. Give the connection Details and name it as NitsWebSLEntities.
Select required tables and procedures.
Build.
Create a stored procedure named nvmsl_GetClient.
ALTER PROCEDURE [dbo].[nvmsl_GetClient]
@ClientID int,
@Active bit
AS
BEGIN
    select c.ClientID,cu.UserName,cu.Password,cu.Email,cu.PasswordQuestion,cu.PasswordAnswer from dbo.nvmsl_ClientUsers cu,dbo.nvm_Client c where c.ClientID=@ClientID and c.Active=@Active and c.ClientID=cu.ClientID
END


Right click on WCFexampleModel.edmx select model browser.
 From the left corner Tree view select nvmsl_GetClient Procedure in stored procedures in NitsWebSLModel.Store.
Right click on nvmsl_GetClient Add function Import.
Select Returns a collection of : Complex
Click the button Get column information.
And click the button Create new complex types.
You will get a name “nvmsl_GetClient_Result” after clicking the above button.

Add the following code in the service

        [OperationContract]
        List<nvmsl_GetClient_Result> Get_Clients(int id, bool status)
        {
            NitsWebSLEntities dc = new NitsWebSLEntities();
            return dc.nvmsl_GetClient(id, status).ToList();

        }


Add the following code in Silverlight page.
          WCFexampleService.WCFexampleClient ws = new WCFexampleService.WCFexampleClient();
            ws.Get_ClientsCompleted += new EventHandler<WCFexampleService.Get_ClientsCompletedEventArgs>(ws_Get_ClientsCompleted);
            ws.Get_ClientsAsync(6,true);


void ws_GetUsersCompleted(object sender, WCFexampleService.GetUsersCompletedEventArgs e)
        {
            UserdataGrid.ItemsSource = e.Result;
        }

How to use Asp.net Membership use in silverlight Business application

Reference: http://msdn.microsoft.com/en-us/gg315205

Open the project in visual studio 2010
Open the  <project>.web projects web.config file.
Find the <system.web> element
Delete the <rolemanager Enabled=”true”> element
Delete the <profile> element and all its children.
Inside the <system.web> element, add the following.
<membership defaultProvider="SlEventManagerMembershipProvider" userIsOnlineTimeWindow="15">
  <providers>
    <clear />
    <add name="SlEventManagerMembershipProvider"
         type="System.Web.Security.SqlMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
         connectionStringName="SlEventManagerDb" applicationName="/SlEventManager" enablePasswordRetrieval="false"
         enablePasswordReset="true" requiresQuestionAndAnswer="true" requiresUniqueEmail="true"
         passwordFormat="Hashed" />
  </providers>
</membership>

<roleManager enabled="true" defaultProvider="SlEventManagerRoleProvider">
  <providers>
    <clear />
    <add name="SlEventManagerRoleProvider"
         type="System.Web.Security.SqlRoleProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
         connectionStringName="SlEventManagerDb" applicationName="/SlEventManager" />
  </providers>
</roleManager>

<profile enabled="true" defaultProvider="SlEventManagerProfileProvider">
  <providers>
    <clear />
    <add name="SlEventManagerProfileProvider" connectionStringName="SlEventManagerDb"
         applicationName="/SlEventManager"
         type="System.Web.Profile.SqlProfileProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
  </providers>
  <properties>
    <add name="FriendlyName" />
  </properties>
</profile>
Find <connectionStrings> section of the web.config.add another entry for the authentication database.

<add name="SlEventManagerDb"
     connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\SlEventManager.mdf;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True"
     providerName="System.Data.SqlClient" />
Run the application.

Displaying links for user based on login
Write the following in MainPage’s constructor

  WebContext.Current.Authentication.LoggedIn += (se, ev) =>
            {
                Link3.Visibility = System.Windows.Visibility.Visible;
                Divider2.Visibility = Visibility.Visible;
            };
            WebContext.Current.Authentication.LoggedOut += (se, ev) =>
            {
                Link3.Visibility = System.Windows.Visibility.Collapsed;
                Divider2.Visibility = Visibility.Collapsed;
            };
If user logged out, user should be redirected to Home or Particular page

            WebContext.Current.Authentication.LoggedOut += (se, ev) =>
            {

                NavigationService.Navigate(new Uri("/Login", UriKind.Relative));
            };