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?


  • 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.

Disable The Visual Studio Hosting Process

The Visual Studio hosting process is used to provide security and performance benefits when debugging Visual Studio applications. However, you can make do without the process. To disable the process select Project -> Properties -> Debug Tab, and then untick the Enable Visual Studio hosting process option.

Build a Website in Visual Studio 2010 ASP.NET, C#, and MVC3.

To build a website using Visual Studio 2010 is very straight forward. You can can powerful results for very little coding effort. This article provides the steps for building a website using Visual Studio 2010 Professional, ASP.NET 4.0, C# 2010, MVC3, and SQL Server 2008 R2 Express Edition.

If you are a student, you can obtain Visual Studio 2010 Professional for free by visiting SQL Server 2008 R2 Express can be obtained by visiting  Microsoft.  Make sure these are installed before continuing with this article. Also, you will need to make sure the instance .\SQLEXPRESS is up and running.

Create an empty database. Open up the Visual Studio 2010 Command Prompt, and type aspnet_regsql. Go through the wizard that pops up to add the Membership API tables to the database.

Create a new Visual Studio 2010 C# ASP.NET MVC3 Website. Change the connection string in the Web.config file by appending the attribute “MultipleActiveResultSets=True” to the end of it. I have called my database Hospital, and the connection string is: "Data Source=.\SQLEXPRESS;Initial Catalog=Hospital;Integrated Security=True;Pooling=False;MultipleActiveResultSets=True;".

Open up the Package Manager Console. Type Install-Package MvcScaffolding. This will install the MvcScaffolding libraries necessary for the next steps.

In the Models folder of your Visual Studio project, add a class and call it HospitalModels. Add the following code:

namespace Hospital.Models
public class Specialism
public int Id { get; set; }
public string Name { get; set; }

The above code is a model. In this scenario it is a medical specialism. In the Package Manager Console type Scaffold Controller Specialism. Once scaffolding has been completed, you should see under Views a folder called Specialism, and the following CSHTML files: _CreateOrEdit.cshtml, Create.cshtml, Delete.cshtml, Details.cshtml, Edit.cshtml, and Index.cshtml.

In order for the created pages to be visual accessible via the home page, you need to modify the “_Layout.cshtml” file under the “Views\Shared” folder. Add the following code under the “About” menu item:

<li>@Html.ActionLink("Specialism", "Index", "Specialism")</li>

The first item in the ActionLink is the text that appears as the hyperlink, the second item is the page to display, and the third item is the folder which contains the required file.

Now you are able to run the project. If you have problems running the project, check your connection string and check the instance of SQL Server Express is running.

Hospital specialisms that you can use as sample data: Audiology, Cardiology, Colorectal, Cosmetic Surgery, Dermatology, “Ears, Nose & Throat”, Gastroenterology, General Medicine, Gynaecology (Women’s Health), Infertility Clinic, Joint and Muscle Clinic, Neurology, Obstetric Scanning, Opthalmology, Othorpaedics, Paediatrics, Pain Management, Physiotherapy, Podiatry, Psychological Medicine, Radiology, Respiratory Medicine, Rheumatology, Sexual Health Medicine, Shockwave Therapy, Travel Clinic, Urology, Varicose Veines, and Vasectomy.

You should be able to add, edit, delete, list all items, and view individual items, and all for little coding effort.

Debugging JavaScript in VS2010

In order to debug JavaScript using Visual Studio 2010, make sure that you have Internet Explorer set as your default browser, and that you have both the internet options “Disable script debugging (Internet Explorer)” and “Disable Script Debugging (Other)” unticked. Within VS2010 under the Tools->Options->Debugging->Just-In-Time entry make use that “script” is ticked.

Also, other sources have stated that “When Silverlight debugging is enabled, it disables ASP.NET debugging.”

Visual Studio 2010 Will Not Allow Files to be Edited

I was doing some testing today of a Windows Phone 7 application. Specifically, I disconnected my computer from the network to test the piece of code that checks to see if the phone has network connectivity. This puts Team Foundation Server into off line mode.

After doing some internet research, I then went back into my Windows Phone 7 project and tried to edit it. It wouldn’t allow me to edit the file and would move to the beginning of the current line when I pressed the enter key. The reason for this is that even though I had finished testing and reconnected my network connection, TFS was still in offline mode.

To be able to edit files that are checked in, it is necessary to click the reconnect icon to reconnect TFS. This fixed my problem.

ASP.NET Technology Considerations

Going forward I will be developing a number of different types of websites using ASP.NET and supporting technology. The last time I developed a commercially used ASP.NET website was an extranet using ASP.NET, XHTML, CSS, JavaScript, VB.NET, and SQL Server 2005 in 2007 using Visual Studio 2003 Professional. Since then technology has moved on. So I have performed some initial research into the different techologies that are currently available that can be utilised to build commercial websites.

The MIX11 video Scaffolding – ASP.NET, NuGet, Entity Framework Code First and More by Steve Sanderson is very interesting. As a result, I am thinking that it may be appropriate to build new websites using ASP.NET 4.0, Razor, the Entity Framework, NuGet, the MVC design pattern with MvcScaffolding, and SQL Server 2008.

Convert Word Document To PDF

In the course of business, there will be times when you want to convert a Microsoft Word document into a PDF document. The easiest way to do this that I have come across is to install OpenOffice. When you open a Word document in OpenOffice, you can save it as a PDF. The conversion is very good.

However, what if you want to do this programmatically from VB.NET? Well, it is very straight forward.

Download and install OpenOffice. You will need a copy of the Java Runtime Edition (JRE). There is a version of OpenOffice that you can download that includes the JRE. Set the PATH environment variable to include the paths to the JRE bin folder, and the OpenOffice program folder. Then download and extract JODConverter. Restart your computer.

When your computer has rebooted, open up a command window. Type the command java -version and press enter. This should output the version of the JRE that is installed on your system. Now type the command soffice and press enter. This should start OpenOffice. Your OpenOffice installation is complete.

Now before you go any further, you have everything you need to convert a Word document to PDF via the command line. The commands to do this are:

"C:\Program Files\ 3\program\soffice.exe" -headless -nologo -norestore -accept=socket,host=localhost,port=8100;urp;StarOffice.ServiceManager
java -jar D:\Tools\jodconverter-2.2.2\lib\jodconverter-cli-2.2.2.jar "D:\Files\Test.doc" "D:\Files\Test.PDF"

To execute this code in a consistent and easy manner from VB.NET is a very simple process. Open up Visual Studio .NET 2010 and create a new VB.NET Console Application. Copy the code below into the Module1.vb file and rename the file to EntryPoint.vb.

Imports System
Imports System.Configuration
Imports System.IO
Imports System.Text
Imports System.Collections.Generic

Public Class EntryPoint

Public Shared Sub Main(ByVal args As String())

Dim batchFileCommandText As New StringBuilder
' Prepare the batch file text.
batchFileCommandText.Append(" ")
batchFileCommandText.Append(" ")
batchFileCommandText.Append(" ")
' Create the batch file and save the batch file text.
Using batchFile As New StreamWriter(ConfigurationManager.AppSettings("BatchFile"))
End Using
' Execute the batch file.
' The conversion is a success, print a message and exit.
System.Console.WriteLine("Conversion successful...")
Catch ex As Exception
End Try
End Sub
End Class

Add an app.config file to your project and include the following application settings.

<clear />
<add key="OpenOffice" value="C:\Program Files\ 3\program\soffice.exe" />
<add key="OpenOfficeParameters" value="-headless -nologo -norestore -accept=socket,host=localhost,port=8100;urp;StarOffice.ServiceManager" />
<add key="JODConverter" value="java -jar D:\Tools\jodconverter-2.2.2\lib\jodconverter-cli-2.2.2.jar" />
<add key="BatchFile" value="D:\Files\convert.bat" />
</appSettings >

Note: If your applications are installed in different locations to the one described above, the you will need to change your app.config file to point to the right locations.

Execute the code now passing in for the parameters the input file followed by the output file. If all goes according to plan, you should now have a generated PDF.