Still updating my Mix 09 Silverlight 3 + RIA Services talk with more fun stuff. Azure represents a general trend in the industry towards a cloud computing model. As much as I love the development phase of projects, the operations side is often the most cost intensify part. With economies of scale, cloud computing has the potential to greatly reduce those costs. I think example I took advantage of Windows Azure to host the web-tier of the application and Sql Azure to host the data. Those are actually independent decisions. You could decide to host one and not the other.
You can see the full series here.
The demo requires (all 100% free and always free):
- VS2008 SP1
- Silverlight 3 RTM
- .NET RIA Services July ’09 Preview
- Windows Azure Tools for Microsoft Visual Studio July 2009 CTP
- Windows Azure Invitation (apply here)
- Sql Azure Invitation (apply here)
So in this example, I can going to move the data from on premises Sql Server to SQL Azure AND move the applogic code from running on my own web server to running on Windows Azure. The main client will stay Silverlight.
Setting up SQL Azure
Once you get an invite code for SQL Azure, you can go to http://sql.azure.com and add a new database, just by clicking add new Database
Then you get a nice connection string..
Then you need to populate the database. If you have an existing database, the best way to do this likely to use Sql Management Studio to get a Sql script and then using ADO.NET to execute that script on this Sql Azure database.
But for no good reason, I wrote a very simple bit of ADO.NET code to read the data out of my local database and insert it into the Sql Azure based one. You can find it in the default.aspx.cs page if you want to check it out.
Setting up Windows Azure
That sets up our database in the cloud, now let’s create a place for our web application to run. Once you get an invite code from Windows Azure you can go in an setup your service. Go to windows.Azure.com and add a new service
Select the Hosted Service
Setting up the Project
Start up Visual Studio as an administrator… the “local cloud” support requires this right now.
Then create a new Cloud Service
For this example, all we need is a Web Role
I renamed “WebRole1” to MyApp.Web to match the pervious examples.
Hitting F5 starts up the “local cloud” and runs it there..
Creating the Application
Now, let’s start building the application. First let’s build out the data layer. I already had a Linq2Sql model from a pervious example, so I just copied that. I did tweek a few of the datatypes to match what I loaded into Azure… Entity Framework would have worked just as well.
Then I changed the connection string in Web.config to match the connection strings of the Sql Azure database.
Now it is just like the original walk through..
Create the Service
Write some code in it…
Now we need to add a Silverlight Project
And associate it with the MyApp.Web project and enable RIA Services.
Now you can simply use the exact same Silverlight client we built before.
You get sorting, paging, filtering, validated editing, batching all with no plumbing code and now, all hosted in cloud!
Deploying to the Cloud
Now that we have our app done, let’s deploy it to the cloud.
First we need to create the deployment package. To do that right click on the MyApp.CloudService project and Select Publish
The publish directory will up in explorer with your application deployment package and a separate settings file
The deployment package is just a zip file that contains the silverlight xap an the code and resources to execute on the server. The settings file contains things like number of front-end servers you want to create, etc.
Now, go back to windows.azure.com and select the project we created earlier.
There are two places for your app to run.. Staging and Production. The idea is you can do testing in the real environment before you switch your live site over.
Select upload to add your project to staging.
The add the package and settings and give it some deployment label to help us keep track of its movements between staging and production.
Then click run to start the instance running. Then it will say “initializing…” for a few minutes
Finally, when it says “started” you can run the app by clicking on the test link:
Next swap this into the deployment stage and you are live!
And we are done!
In this section we talked about how to deploy your RIA Services application to the cloud using Sql Azure for the data and Windows Azure for the web tier. You can mix and match those however you want.
Also, check out Nikhil’s example on Azure, it uses Windows Azure table storage which is very cool as well.