As part of my demo preps for all the conferences I’ve spoken at recently I’ve been deploying my LightSwitch apps to Azure websites and I can honestly say that it is by far the easiest way to get a LightSwitch application up and running. Of course you can always manually set up your own server, database and network if you want a purely internal business app like I’ve showed in these deployment posts. However, it’s always hard to troubleshoot what goes wrong when a deployment goes bad because everyone’s environment is a little bit different. The great thing about Azure websites is the environment is hassle-free and already ready for you to deploy your LightSwitch applications.
In this post I’ll detail step-by-step how to deploy a LightSwitch application to Azure websites. But first, you may be wondering what the heck is an Azure website and what’s the difference between that and a cloud service? LightSwitch applications can be deployed to both through the Publishing Wizard, but why would you choose one over the other?
Azure Cloud Services provide reserved, infinitely scalable, n-tier options running on a Platform as a Service (Paas). Azure Websites are for quick and easy web application and service deployments. You can start for free and scale as you go. So if you do not need all the other advanced services like Business Analytics, Service Bus, or Identity that the Azure cloud services provide and you only have a LightSwitch application to deploy, then an Azure website is the right choice.
If you’re interested in deploying to cloud services see Andrew & Brian’s post: Publishing LightSwitch Apps to Azure with Visual Studio 2012
Step 1: Build Your App
Of course we’re going to need an application to deploy ;-) so in this post I’ll use the Contoso Construction sample that is available on the Samples Gallery. This is a good advanced sample that uses external data sources as well as some extensions so it’s a good example of a typical LightSwitch application out there in the real world.
I want to host the application as a desktop client with the services and SQL database in Azure. Azure websites are perfect for this. Since the desktop client of a LightSwitch application is just a Silverlight application it’s the same type of hosting; the XAP file sits on the web server and when a user navigates to the URL, it is automatically installed into their Windows start menu just like any other program. The reason why we need to deploy this as a desktop app is because we do a lot of Office automation in this sample using the Office Integration Pack extension and so we need to run as a full trust Windows application. Silverlight gives us the ease of web deployment with the benefits of running full trust out-of-browser.
Step 2: Sign Up for Azure Websites
Before you can publish to the Azure website you need to sign up. Once you sign up and create a subscription you will have access to your own portal. From the portal you can then manage all your cloud services, websites and databases all in one place.
Step 3: Create a New Website & Database
Once you get to your portal, select the WEB SITES tab and click NEW.
All LightSwitch applications need a SQL database so make sure you create a corresponding database for your new website by selecting that option.
Next, specify the name and location of your website. Make sure you pick a location near most of your users.
Next create your database server (if this isn’t your first time, you can select an existing server as well). Make sure the database server is in the same region as your website for the best performance.
Click OK and your website and database will be set up. Lastly, in order to publish the database from Visual Studio, you will need to make sure the database server trusts your computer by adding a management certificate. The easiest way to do this is to select the database in the portal and click MANAGE at the bottom. This will prompt you to create the certificate automatically if you need one.
Step 4: Publish
In Visual Studio, make sure you’re configuration is set to Release and then right click on your project and select Publish from the menu. You can also go to the Project Properties – Application Type section and click the Publish button to launch the Publish Wizard. (If you’re configuration isn’t set to Release then the Publish Wizard will give you a warning.)
The first question you’re asked is what type of application you want to publish. In our case, we want to select “Desktop”. Notice however that you can also deploy your application as a browser application as well as just the services (middle-tier). Deploying just the services makes sense if you have only external OData clients accessing your service. The LightSwitch OData services are always published, but you can choose whether the LightSwitch client is published or not via this dialog.
Next you need to specify where to deploy the application. You can deploy a LightSwitch application in multiple ways. You can deploy it as a simple two-tier (traditional client-db server) application, or you can deploy as a scalable n-tier architecture in which case you can select to deploy to an IIS web server or Windows Azure. In our case we will select Windows Azure.
Next you will need to specify your Azure subscription information. Simply click the link to sign in to download your credentials. Then click Import to load them into the LightSwitch Publish Wizard. Once you do that, your settings will be loaded for the subscription you set up and automatically selected. (My Azure subscription name is “Demo Projects”).
Next we need to specify the service type. Here is where we can choose to deploy to an Azure cloud service or an Azure website. Select Website and click next.
Next we need to specify the Website we want to publish to. This will be the same website you specified in the portal.
Next we need to specify security settings which has multiple parts. First, if you have specified to use Authentication in your application you will need to specify the application administrator who will have first access to the app. This user is responsible for adding Users to Roles in order to set up access permissions. (For more info on LightSwitch Access control see: Securing Access to LightSwitch Applications). For the Contoso Construction application, it uses Forms Authentication so I’ll need to specify the App Administrator here.
You’ll notice two other tabs on the Security Settings section of the wizard. The HTTPS tab specifies if traffic should be sent over a secure channel SSL. It is highly recommended that you set up secure communication between your LightSwitch data services on your middle-tier and any client accessing them. Otherwise malicious users could sniff network traffic and see the data that you were transferring from the client to the services. Fortunately, Azure websites are set up to handle HTTPS traffic so select that option.
On the last tab of Security Settings, you specify a digital signature for your client desktop application. This is only necessary if:
- You are publishing a desktop application
- You want to be able to publish updates automatically to desktop users
If you do not specify a digital signature on a desktop app then when you update the application then users will have to uninstall and reinstall the app before they can use it. Specifying a digital signature is a good idea in general anyways so that users see a trust prompt when installing. You should use a digital signature from a trusted certificate authority like VeriSign. However you can also create internal certificates and then install them into the trusted root cert store on the client machines (Internet Options – Certificates). This is a good option for testing or for internal applications. For this example, I have already created a test certificate and installed it into my trusted root store so I can select that here.
Next we need to verify the connections to our database and any external data sources (if any). When we created a corresponding database for our Website in the portal, the database information is picked up in the Publish wizard. Make sure you check “Publish database schema” so that the database is created.
The Attached Data Sources tab will appear if you are using any external data sources, like OData Services or other external databases. You can verify those connections here. The Consotso Construction app uses a OData service from the Windows Azure Marketplace which contains free (as well as pay) data sets that you can use to enhance your LightSwitch applications.
Finally, a summary page is displayed. Click Finish and your app will be deployed to Azure Websites in about 2 to 3 minutes.
You can watch the deployment progress in the Output window in Visual Studio. It should be pretty quick, I’ve never seen it take longer than 2 minutes for my apps. Once complete the portal will open and you can hit the URL you created to launch your application which you can find to the right of the Website entry in the portal.
UPDATE: If you are using Visual Studio 2012 Update 2 or higher and have upgraded your LightSwitch project to V3 or higher (or added an HTML Client project), then you will need to navigate to the corresponding client subfolder. i.e. myazurewebsite.net/Client for desktop, myazurewebsite.net/HTMLClient for HTML.
With a desktop application it will prompt users to install the application like so.
Once you install the app it will launch. Users can then re-launch it from the start menu at any time. An icon is also placed on the desktop. You can uninstall it via Add/Remove Programs just like any other application. Additionally if you make changes and then republish the application to Azure, next time users launch the application it will be automatically updated and users will be directed to simply reopen it.
Of course, you can also host in-browser applications in Azure exactly the same way. In that case, users will use their favorite browser to navigate to the URL when they want to use the application. Also keep in mind that in-browser apps do not run in full trust so you can’t do COM automation like we are in this sample.
I hope this shows you how easy it is to get started with Azure websites to host your LightSwitch applications. LightSwitch makes it super fast and simple to develop business applications and now with Azure websites they can be deployed even faster. For more information see the Visual Studio LightSwitch Developer Center and the Windows Azure Websites offering.