- Introduction
- Preparing the SQL Azure Server
- Implementing Authentication
- Publishing to Windows Azure with the LightSwitch Publish Application Wizard
- Managing SQL Azure Logins and Users
- Conclusions
Publishing to Windows Azure with the LightSwitch Publish Application Wizard
Since its first version, Visual Studio LightSwitch always had integrated support for deploying applications to Windows Azure. The very good news is that this integrated support has been enhanced in Visual Studio 2012 to include the HTML client.
Follow these steps to start publishing your apps to Windows Azure:
- In Visual Studio 2012, select Build > Publish to start the LightSwitch Publish Application Wizard. You've used this wizard previously to deploy applications to a web server, but this time you'll see how Windows Azure can make your life easier.
- When the wizard starts, leave the first dialog unchanged and move to the second one. Select Windows Azure as the hosting environment, as shown in Figure 3.
- Click Next. Now you're asked to specify the publish settings, as shown in Figure 4.
- If this is the first time you've published an application to Windows Azure, click the "Sign in to Download Credentials" hyperlink. The Windows Azure site will open, and your web browser will immediately ask where to save a file containing the publish settings (with the extension .publishsettings). Select a location and save the file.
- Go back to Visual Studio, click Import, and select the downloaded .publishsettings file.
Figure 4 Specifying publish settings.
If everything worked correctly, Visual Studio will automatically import your settings, and you won't have to enter them manually!
The next phase is specifying the service type for the project. Two services are available: Web Site and Cloud Service. The Web Site service is a prepackaged environment, ready to host a web application with its services. This is the ideal choice, especially if you don't have experience with Windows Azure, so select this option (see Figure 5).
Figure 5 Selecting the Web Site service type.
Visual Studio LightSwitch cannot create a site for you. This makes sense, because it's your responsibility to specify the site's name (especially an alternative name, if the one you wanted is already in use) and region (the nearest location to you). So you need to create a web site before you can continue with the LightSwitch Publish Application Wizard. Follow these steps:
- In your web browser, open the Windows Azure Management Portal.
- Click +NEW at the bottom of the page.
- A kind of pop-up appears. Select Web Site and then Quick Create, and specify the appropriate URL and region, as shown in Figure 6.
- As Figure 7 shows, after you click the Refresh button in the wizard, you'll be able to select the newly created web site. Do that now.
- The next dialog of the wizard consists of three tabs:
- Application Administrator. This tab requires you to specify credentials for the application's administrator. This isn't new at all. Since it's the first time the app is being published to the new environment, provide your own administrator credentials.
- HTTPS. LightSwitch applications can use secure, encrypted connections via the HTTPS protocol, so that data and login credentials are protected. If you have your own in-house server, you have to configure the operating system to accept HTTPS connections. But Windows Azure is already configured manually to accept secure connections, so you simply need to select the HTTPS option, as shown in Figure 8.
- Digital Signature. This option isn't required for this article.
- In the next dialog of the LightSwitch Publish Application Wizard, you specify the connection strings. Figure 9 shows an example (my personal data is blacked out).
- The user connection string is what the application will use in production, and it typically doesn't have administrator privileges—only read/write permissions. The second connection string is required to generate the database on SQL Azure, and it must have administrator privileges. For the sake of simplicity in this first deployment, we'll use the administrator connection string for both options. Later I'll show you how to supply a connection string with limited permissions.
- There are some considerations to keep in mind at this point:
- We want to see how LightSwitch creates a SQL Azure database automatically, so we'll assume that this is the first time you're publishing to Azure, and you have no other users or logins on the SQL Azure server. Because it's the first time, you have to use the administrator connection string.
- By making LightSwitch do the work of creating the SQL Azure databases, you save a lot of time. In fact, creating a SQL Azure database from scratch could be a real effort, and the same would be true if you want to import an existing database, which requires writing lines of Transact-SQL language or using specialized tools such as the SQL Database Migration Wizard.
- Things get easier if you already have users and logins on your SQL Azure server. At that point, you can simply assign an existing user to the new database.
- Specify your connection strings in the way you already know, using the Connection Properties dialog, as shown in Figure 10.
- The server name takes the following form:
- SQL Azure uses SQL authentication unless you're working with an Active Directory system, so you can choose the Windows option.
- Enter the user name and password you provided when creating the server, and type a database name, such as OrdersManagement, in the Connect to a Database box. (You're creating a new database, so you have to enter its name manually.) When you're finished, click OK.
- Complete the LightSwitch Publish Application Wizard, as described earlier.
- After a few minutes your application will be ready to run on Windows Azure. (The length of the wait depends on the speed of your Internet connection.) The only thing you have to do now is type the application's URL into your web browser's address bar. Figure 11 shows an application running on Windows Azure after the user has logged in.
Figure 6 Creating a new site.
Figure 7 Selecting the target web site.
Figure 8 Selecting the HTTPS secure connection option.
Figure 9 Supplying user and administrator connection strings.
Figure 10 Entering the connection string.
servername.database.windows.net
Figure 11 This sample application is running on the cloud.
If you followed the steps in Part 2 of this series, you can launch the Silverlight desktop client from Azure, managing users as described previously.