Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Tools

Building Line-of-Business Apps with Silverlight 2


Anthony Lombardo is the lead Technical Evangelist at Infragistics and recipient of the ASP.NET MVP Award from Microsoft. Tony co-runs the Central Jersey .NET Users Group.


Line-of-business applications have a notorious reputation for being all business and no pleasure. The fact is that "user experience" has never really been a top concern when developing line-of-business (LOB) applications. While many LOB-style applications are putting an increasing emphasis on usability, they often fall short on appeal. User experience is actually a combination of both usability and appeal, as in Figure 1.

Figure 1

LOB applications classically fall somewhere between "Please shoot me!", and "Day Job". But there's no reason they can't fall into the "First Love" category; a perfect mix of usability and appeal.

WPF has made it much easier for desktop applications to move into the "First Love" category of Figure 1, through its rich media capabilities, animation support, and declarative model. These same characteristics are driving differentiating experiences with Silverlight 2 as well, making "First Love" line-of-business apps for web client easier to build. There's no question that AJAX has fueled some of the richest Internet applications seen, but Silverlight promises to go even further. Silverlight not only makes creating rich user experiences easier, but also breaks through animation and media barriers where AJAX alone could not. But even beyond user experience, Silverlight's programmability alone gives it a leg up on the classic (and error prone) Javascript ways of the past. Understanding the advantages that Silverlight offers in the world of user experience is certainly important, but what's even more important is understanding how to perform classic line-of-business functions in this new framework. After all, the best user experience in the world isn't going to help an application that lacks required functionality.

Getting Started

The first thing to remember about a Silverlight application is that your code is running mainly on the client-side. This setup requires a solid communication layer connecting the client and the server, which is typically accomplished through web services; mainly WCF. Whether your databinding, authenticating, or even validating, you'll be talking through a web service at some point. Of course, you could use AJAX (XmlHTTPRequest) to communicate with the server; scripting the results to your Silverlight code, but that's best left to the hard core scripters out there.

Authentication

Any line-of-business application is going to have a requirement for some form of authentication. While Silverlight doesn't have authentication built into its core, you can easily re-use the ASP.NET authentication model.

Authentication for a Silverlight application is set up just like a typical ASP.NET application. Permissions can be set for pages and directories, using rules and roles through the web.config file. For most scenarios, Windows authentication will be used, for its tight integration between roles and ActiveDirectory. However, if you choose to use forms-based authentication, you'll need to add a way for the user to supply credentials to your application. This can be done through a typical ASP.NET login page which acts as the gateway to your application. However, if you're creating a full-screen Silverlight application, it's better to provide a login experience which more closely matches the rest of your application. Enter WCF once again.

ASP.NET 3.5 includes WCF services for Authentication, Roles, and Profiles. These services can easily be added to your application in a couple of steps. Because the service is already included in the .NET Framework, you simply need to create an endpoint for the service. The first step is to add the .svc file to your web site. You will want to add a plain text file in this case rather than using the "Silverlight Enabled WCF Service", since you don't actually need a code behind file. Listing One is an example of the AuthenticationService.


<%@ ServiceHost Language="C#" Debug="true" Service="System.Web.ApplicationServices.AuthenticationService" %>

Listing One

Aside from creating the service wrapper, you must also enable the service in the web.config file. This requires adding the service definition, bindings and behaviors as well as enabling the AuthenticationService through the system.web.extensions tag. Full details can be found in Listing Two.

<system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="authBinding">
                    <!-- Transport security is recommended -->
                    <security mode="Transport"/>
                </binding>
            </basicHttpBinding>
        </bindings>

        <behaviors>
            <serviceBehaviors>
                <behavior name="AuthenticationServiceTypeBehaviors">
                    <serviceMetadata httpGetEnabled="true"/>
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />

       <services>
            <service name="System.Web.ApplicationServices.AuthenticationService"
                           behaviorConfiguration="AuthenticationServiceTypeBehaviors">
                <endpoint contract="System.Web.ApplicationServices.AuthenticationService"
                          binding="basicHttpBinding" bindingConfiguration="authBinding"
                          bindingNamespace="http://asp.net/ApplicationServices/v200"/>
            </service>
        </services>
    </system.serviceModel>
    <system.web.extensions>
        <scripting>
          <webServices>
            <authenticationService enabled="true" requireSSL="false"/>
          </webServices>
        </scripting>
  </system.web.extensions>
Listing Two

With authentication, role and profile services all in place on your web site, you can now add the appropriate service references to your Silverlight application and get to work writing some code.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.