Step-by-Step: How to Publish to Windows Azure (Andy Kung)

Step-by-Step: How to Publish to Windows Azure (Andy Kung)

Rate This
  • Comments 20

UPDATE: These steps have been simplified with the release of Visual Studio 2012. Please see: Publishing LightSwitch Apps to Azure with Visual Studio 2012

--------------------------

One of the many features introduced in Visual Studio LightSwitch Beta 2 is the ability to publish your app directly to Windows Azure with storage in SQL Azure. We have condensed many steps one would typically have to go through to deploy an application to the cloud manually.

In this tutorial, we will deploy a LightSwitch web application with Forms authentication to Windows Azure and SQL Azure. This walkthrough assumes that you already have a Windows Azure subscription and basic knowledge of Windows Azure. If you do not have a subscription, you can sign up for an account here. The sign up page will explain different pricing models as well as a Free Windows Azure trial!

Configuring Windows Azure

Before we publish an application from LightSwitch, let’s first make sure we have the necessary information and Azure configuration. Sign in to your Windows Azure account via Windows Azure web portal.

clip_image002[8]

Subscription ID

We will need the Windows Azure subscription ID to publish from LightSwitch. To find it, click “Hosted Services, Storage Accounts & CDN” tab on the left side of the portal.

clip_image004[6]

Select “Hosted Services” on the side menu. Select the subscription node in the middle pane. You will find your Subscription ID on the right side of the portal.

clip_image005[4]

Hosted Service

With the “Hosted Services” selected on the side menu, you will see a list of existing hosted services. A hosted service is the actual website that will be hosting your LightSwitch application. You will need a hosted service to publish from LightSwitch. To create a new hosted service, click “New Hosted Service.”

clip_image006[4]

In the “Create a new Hosted Service” dialog, specify a service name and a unique URL prefix. The URL will be used to access your LightSwitch application once it has been deployed. Next, choose a region to host the service. I’ll pick “North Central US.” Select “Do not deploy” since we’re deploying from LightSwitch instead of this web portal.

image

You will see the newly created service in the list.

clip_image008[4]

Storage Account

You will also need a storage account to publish from LightSwitch. The storage account is used to store your LightSwitch application as it is being uploaded to Windows Azure. Select “Storage Accounts” on the left menu to see a list of existing storage accounts. To create a new storage account, click the “New Storage Account” button.

clip_image010[4]

In the “Create a New Storage Account” dialog, specify a unique URL name. I’ll choose “North Central US” again. Click Create.

image

The newly created storage now shows in the list.

clip_image013[4]

Database Server

Next we need to make sure you have a database server set up. You only need to do this once per subscription. If you have not set up a database server, click Database in the left menu. Select your subscription account and click “Create” button.

clip_image014[4]

Specify a region and click Next. Notice that I used the same “North Central US” region for hosted service, storage account, and database server. This is to ensure that my web role instance lives in the same region as the SQL Azure database to reduce latency on database calls and bandwidth charges.

clip_image015[4]

Specify a name and password for the database administrator and click Next.

clip_image016[4]

The next page of the wizard will set up firewall rules for your SQL Azure account. Check “Allow other Windows Azure services to access this server” to allow your LightSwitch application to connect to this database server.

clip_image017[4]

You will also need to add a rule for your development machine to allow the LightSwitch Publish Wizard to update your database. Click Add to add a rule. In this example, I am going to allow all machines in my domain.

clip_image018[4]

Click OK and then click Finish.

Once you have created a database server, select the database server node in the web portal. The Server name will be the Fully Qualified DNS Name on the right side. The administrator login will be listed on this page as well. You will need the server name and login information when you publish from LightSwitch.

clip_image019[4]

Deploying a LightSwitch App

Now create a LightSwitch project with Forms authentication. I have a very simple LightSwitch application called “HelloWorld.” It has only one table and one screen. I’m ready to publish… TO THE CLOUD!

Right click on the project node in the Solution Explorer and select Publish.

clip_image020[4]

Step 1: Client Configuration

The Publish Wizard now appears. It will guide us through several steps. Our first decision to make is to publish as a desktop or web application. LightSwitch supports publishing browser-based and desktop applications to the cloud. In this example, we will choose Web application and click Next to Step 2.

clip_image021[4]

Step 2: Application Server Configuration

Since we want to host the application in Windows Azure, select Windows Azure option and click Next to Step 3.

clip_image022[4]

Step 3: Connect to Windows Azure

In order to connect to Windows Azure, you need to provide your Windows Azure subscription ID and a management certificate. We already found the subscription ID in the Windows Azure web portal earlier. Go ahead and fill it in.

clip_image023[4]

The management certificate is used to authorize your computer to update hosted services on Windows Azure. You can select an existing certificate from the dropdown menu. To create a new certificate, select “Create new self-signed certificate” from the dropdown menu.

clip_image024[4]

Name the certificate and click OK.

clip_image025[4]

The Windows Azure certificate store must contain a copy of the certificate. Therefore we need to upload the certificate we just created to Windows Azure. Click “Copy Path” button to copy the location of the certificate and go back to Windows Azure portal.

clip_image026[4]

In the Windows Azure portal browser window, select “Management Certificates” to see a list of existing certificates. Since we want to add a new one, click “Add Certificate” button.

clip_image027[4]

In the Add New Management Certificate dialog, click “Browse.”

clip_image028[4]

Paste the location of the certificate in “File name” and click Open.

clip_image029[4]

Click “Done” to add the certificate. You will see the newly added certificate in the list.

clip_image030[4]

Back in LightSwitch, click Next in the Publish Wizard to Step 4.

Step 4: Azure Service Configuration

In this step, we need to specify the hosted service, storage account, and environment information for the deployment. We’ve already created the hosted service and storage account in the Windows Azure web portal earlier and you should see them in the dropdown menus. You can choose the environment to Staging or Production. In our example, we will keep it as Production. Click Next to Step 5.

clip_image031[4]

Step 5: Security Settings

When deploying to Azure, LightSwitch requires HTTPS for secure connections to your application. This requires the use of an SSL certificate. The dropdown will list all SSL certificates that are already uploaded to Windows Azure. LightSwitch allows you to upload an existing SSL certificate (or one from a licensed vendor such as VeriSign). In our case, we’d like to test it with a self-signed certificate. Select “Create new self-signed certificate” in the dropdown menu. Please note that since it is self-signed, the published app may result in warnings from your browser.

clip_image032[4]

Fill out the information in the dialog and click OK.

clip_image033[4]

The self-signed certificate is now created and selected in the dropdown menu. Click Next to Step 6.

clip_image034[4]

Step 6: Database Connection

We now need to specify the connection information to SQL Azure. LightSwitch requires two connection strings in the Publish Wizard: an administrator connection and a user connection. The administrator connection will only be used by the Publish Wizard to create or update your database. The user connection string will be used by your LightSwitch application to connect to the database. In the LightSwitch Publish Wizard, click the “…” button for the administrator connection.

clip_image035[4]

In the Connection Properties dialog, enter the server name and login info. We’ve already gotten this information from the Windows Azure web portal earlier. Give the database a name. Click OK.

 clip_image036[4]

The User connection will be set to the same by default. For security purposes, create a separate username and password for the user connection string. Click “Create Database Login” button.

clip_image037[4]

Specify a new user login and click Create. Then click Next to Step 7.

clip_image038[4]

Step 7: Authentication

We have designed this application to use Forms authentication. Therefore we need to create an application admin account so you can log in to your app after publishing. When finished, click Next to Step 8.

clip_image039[4]

Step 8: Specify a Client Application Certificate

You can choose to sign the Silverlight client application (Xap file) you are deploying. It will encrypt your client application. In our example, we will leave it unchecked. Click Next to Step 9.

clip_image040[4]

Step 9: Summary

The last step shows you a summary of what you’re about to publish. FINALLY! Click Publish.

clip_image041[4]

It will take about 5 minutes to publish to Windows Azure. You can see the status at the lower left corner of the LightSwitch IDE. Once it’s published, the Windows Azure web portal will launch.

clip_image042[4]

In the Cloud

In the Windows Azure web portal, you can now see the application published under your hosted service. It takes about 10 to 15 minutes for the app to finish initializing. Once it is ready. Click on the DNS name link on the right side to check out the live website.

clip_image043[4]

Since we used a self-sign SSL certificate (in Step 5), IE will warn about the security risk. Click “Continue to this website.” If you have used a licensed SSL certificate, you will not see the warnings.

clip_image045[4]

The web application starts up showing you the log in screen. Type in the administrator credential you created in Step 7 and click “Log In” button.

clip_image047[4]

Voila! We have a web application hosted in Windows Azure and SQL Azure with Forms authentication!

clip_image049[4]

Conclusion

Starting with LightSwitch Beta 2, you now have the ability to publish your desktop and browser-based applications to Windows Azure and SQL Azure. I’ve detailed all the steps necessary to get started with Azure and deploy your first application. Once you have an Azure account and services set up, the republishing of the application is easy. Have fun building cloud-based applications with Visual Studio LightSwitch!

-andy

Leave a Comment
  • Please add 6 and 7 and type the answer here:
  • Post
  • Is there a way to get azure working with claims based authentication so i can use the ACS appfabric (already connected to my AD with ADFS 2.0)

  • Sorry i meant Lightswitch working with claims based authentication so i can use azure's ACS

  • Sorry i meant Lightswitch working with claims based authentication so i can use azure's ACS

  • When I attempted to publish my application, I received the following error.  Any idea what this means?

    Error 1 An exception occurred when deploying the database for the application.

    Sql Server version not supported.

    11.00.1467 C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\LightSwitch\v1.0\Microsoft.LightSwitch.targets 1114 10

  • @Gregory, this issue has been addressed. Please see the post:

    social.msdn.microsoft.com/.../a71a4e75-e584-4869-aba8-5f84abb0454f

    Please let me know if that does not help.

Page 2 of 2 (20 items) 12