Silverlight with WCF Services and SQL LocalDB Development and Deployment using CassiniDev.


Problem: You are required to deploy a Silverlight application that accesses a database via WCF Services onto a standalone computer that does not have IIS, IIS Express, or SQL Server Express installed.  Your end users are people with very limited or no real technical background that find even simple day-to-day IT tasks difficult. What database and web server do you use, and how can you make the installation as easy as possible for your end users with little, or preferably no configuration?

Solution.

  • Install SQL Server 2012 or higher on your development computer.
  • Connect to the LocalDb server instance in management studio using: (localdb)\v11.0.
  • Create a new query and enter the following command to create     your database:

    create database databaseName on (name=’databaseName’, filename=’fileLocation\fileName.mdf’)

  • Create your tables.
  • Create a new Visual Studio Silverlight with WCF RIA Services project.
  • Right click on the web project and select Manage NuGet Packages…
  • Select the online option and type entityframework.
  • Install EntityFramework.
  • Add a model.  The server name should be: (localdb)\v11.0.
  • Build your project.
  • Create your domain service.
  • Build your project.
  • In your Silverlight application import the System.ServiceModel.DomainServices.Client namespace, and the namespace of your web project.
  • Create a member variable for your domain context and IEnumerable of your domain object.
  • In the appropriate method that will instantiate the domain service add the relevant EntityQuery and LoadOperation lines of code.
  • Add you method that will handle the LoadOperation.Completed event, check that args is not nothing.
  • Use your entities as required.
  • Now add a Windows Form application.
  • Download and install CassiniDev.
  • In your Windows Forms application add a reference to the CassiniDev4-lib.dll.
  • For the tutorial on Using CassiniDev to host ASP.NET in your application.
  • Build your solution.
  • Copy the deployable portions of the web project into the WebContent folder located in the Windows Forms executable’s root folder.

On the client computer that you are going to deploy the solution on you will need to install:

  • Silverlight 5;
  • the .NET Framework 4.02 update (NDP40-KB2544514-x86-x64.exe);
  • and the SQL Server Local Database (SqlLocalDB.msi).

There is the Express Edition of InstallShield which is free to use.  Use this to create a Basic MSI project that will silently install the above components, and copy your application onto the client computer.  Create a desktop shortcut.  Run the executable from the shortcut to test that the application is working.

Advertisements