New Posts New Posts RSS Feed: New Silverlight "Business Application" templates shipped with v6.0.6
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

New Silverlight "Business Application" templates shipped with v6.0.6

 Post Reply Post Reply
Author
ting View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 27-Mar-2009
Location: San Francisco
Posts: 427
Post Options Post Options   Quote ting Quote  Post ReplyReply Direct Link To This Post Topic: New Silverlight "Business Application" templates shipped with v6.0.6
    Posted: 20-Oct-2010 at 3:30pm

The 6.0.6 release contains new Silverlight "Business Application" project templates.  These templates are similar to the templates you may have seen or used with Microsoft RIA Services:  the same navigation and theming are used, but we've implemented user authentication and registration using DevForce.  As with the standard DevForce Silverlight Application template, all DevForce references are already set, and the web.config, global.asax and default.aspx are configured as you would see in the standard application.  You should be all set to add an Entity Model and start coding, but here's more information to get you started.

ASP.NET Security and SQL Express
 
The user authentication and registration pieces are using ASP.NET Security services (Membership, Profile and Roles).  These default to using a SQL Express database.  If you'd like to use your SQL 2008 (or 2005) database instead, you have a few options:
  • Modify the web.config to specify a correct LocalSqlServer connection string.  For example:
           <connectionStrings>
              <remove name="LocalSqlServer" />
              <add name="LocalSqlServer" connectionString="data source=.;Integrated Security=SSPI;Initial Catalog=aspnetdb;" providerName="System.Data.SqlClient"/>
           </connectionStrings>
  • Modify your machine.config to re-point the LocalSqlServer connection string defined there to your SQL Server.  If you're going to take this step we assume you know what you're doing, so we won't offer any further instruction here. 

Where to get the database?  

We've got a sample used with our Silverlight Security samples, which you can find here:http://drc.ideablade.com/xwiki/bin/view/Documentation/Code_ASPNETMembershipAndRoles
You can also build one from scratch with Microsoft' guidance:  http://msdn.microsoft.com/en-us/library/x28wfk74.aspx

Note if you attempt to login or register a new user and you do not have SQL Express, and have not made the above changes, then these actions will fail.  Depending on what you're doing you'll likely get a "Provider failed on open" error.  If you would like to use the BAT without the login processing, or with your own login logic, you can make the appropriate modifications.  Continue reading for a description of the BAT contents, and contact us if you have any questions.

How do these templates compare with those from RIA Services?
  • What's the same
    • All of the assets and resources are unchanged, as well as helpers, controls, and libs.  Themes, navigation, and basic functionality are the same.
  • What's different
    • app.xaml code-behind now adds the AuthenticationManager.Current to application resources, and does a "LoadUser" call to try to obtain existing credentials (when using Windows authentication, or a persistent cookie from another Forms authenticated session exists).  The current user is always accessible via AuthenticationManager.Current.User.
    • The primary area of change is in the Login model and views:
      • The LoginInfo and RegistrationData classes are still in the Model, but they're now simple types (they are not DevForce entities) backed by a simple base class performing DevForce validation for property setters. 
      • The views should all look and function the same.  We replaced much of the logic scattered between the code-behind and the entities in the RIA templates with simple view models to make modifications easier.
  • What's new

The AuthenticationManager in the Silverlight project, and the RegistrationServices in the web project, handle login and new user registration. 

In DevForce, every EntityManager must be "logged in" in order to communicate with the BOS or access the data source: if you don't call Login (or otherwise provide credentials), then DevForce will do an "implicit" login for you, usually resulting in a guest login.  If your application uses multiple EntityManagers you likely gather credentials once, and then use the EntityManager copy constructor or its LinkForAuthentication method to "pass the credentials around", so that each EM does not need to re-login.  (What's passed around is actually a token, called the SessionBundle, not the actual login credentials.)

The AuthenticationManager helps alleviate this extra work, via its implementation of the new IAuthenticationManagerinterface.  DevForce will automatically search for an implementation of this interface, and if found use it whenever implicit login is needed.  As shown in the template, you can gather credentials and login once using the AuthenticationManager, and any other EntityManager you use within your application will obtain its credentials via the AuthenticationManager in its LinkAuthentication method.

If you're interested in the new Coroutine support in DevForce (and if you're not you should be!), you'll find two easy to digest uses of it in the AuthenticationManager's Login and RegisterUser methods.

The RegistrationServices class in the web project holds an RPC method called CreateUser which is called from the client to perform new user registration.  The CreateUser logic uses ASP.NET services to register the new user.  Since you'll likely have your own roles and Profile information, you'll need to modify this logic for your needs.

Troubleshooting

  • There's a User class defined which extends the DevForce UserBase  to add a sample ASP.NET Profile property.  Beware of type name collisions if you add an Entity Model which also contains a "User" class.  (As an example, NorthwindIB includes a User table.)  The User class here is defined in the Models subfolder, but you can always move or rename either the namespace or the class, or get rid of it altogether if you don't need to extend the base class.
  • The AuthenticationManager used in the Silverlight application to provide common login and registration functions is using an EntityManager under the hood. DevForce will always make the first EntityManager created the "Default" manager.  If your code is using the DefaultManager static (and you really shouldn't) then be sure to set the DefaultManager to your own sub-classed EntityManager.  If you don't, you'll be wondering where all those handy "entity set" queries have gone.

We don't yet have VB versions of these templates, but will in the 6.0.7 release.


Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down