Business Apps Example for Silverlight 3 RTM and .NET RIA Services July Update: Part 23: Azure

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):

  1. VS2008 SP1
  2. Silverlight 3 RTM
  3. .NET RIA Services July '09 Preview
  4. Windows Azure Tools for Microsoft Visual Studio July 2009 CTP
  5. Windows Azure Invitation (apply here)
  6. Sql Azure Invitation (apply here)


Check out the live site (of course, hosted on Azure) Also, download the full demo files

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

<add name="NORTHWNDConnectionString" connectionString=";Database=northwind;User ID=[add userid];Password=[add password];Trusted_Connection=False;"
  providerName="System.Data.SqlClient" />

Now it is just like the original walk through.. 

Create the Service


Write some code in it…


public IQueryable<SuperEmployee> GetSuperEmployees()
    return this.Context.SuperEmployees
               .Where(emp => Convert.ToInt32(emp.Issues) > 100)
               .OrderBy(emp => emp.EmployeeID);
public void InsertSuperEmployee(SuperEmployee superEmployee)
public void UpdateSuperEmployee(SuperEmployee currentSuperEmployee)
    this.Context.SuperEmployees.Attach(currentSuperEmployee, this.ChangeSet.GetOriginal(currentSuperEmployee));

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


Select deploy..


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. 

Comments (9)

  1. Ted Howard says:

    Awesome tutorials. I can’t read them all, but I know there’re here now in case I need them someday. Thanks for the user education resource.

  2. nisbus says:

    Thanks for the tutorials they’re awesome (can’t wait for the next one).

    I still haven’t received my token for the SQL Azure service but can’t wait to get cracking with this.

    How about a tutorial on having both a webrole and a workerrole for this demo. How would you handle multiple workerroles that read from the queue and submit data?

    ex. user imports an excel document to the SQL server and the webrole reads each row and sends it to the queue.

    On the other end the workerroles are listening and storing the data.

    That would be useful 🙂



  3. nisbus says:

    Btw, Add new doesn’t seem to work in the live demo?

  4. BradA says:

    > Btw, Add new doesn’t seem to work in the live demo?

    nisbus  – Add seems to work in my testing.. I just add a super hero named "Brad Abrams"..  Remeber number of issues needs to be greater than 100 to show up..  

  5. DaveSn says:

    Brad, these are great, thanks.

    I know you gave a link to Nikhil’s blog that has an example using Azure Tables, but it’s not in the same format or style as yours and has lot’s of other different topics as well.

    Can you add to your series how to just move your RIA sample to use Azure Tables?

    I also agree with nisbus – I know enough about Azure Queues to know that I don’t understand them and that I should be using them. How would I migrate your samples to use Queues?

  6. nisbus says:

    lol, sry add new works just fine.

    I didn’t realize there was more than 1 page and I was on the last page 🙂

    my bad

  7. yonzi says:

    good tutorial, r’u have a Pdf version ?

  8. Larry says:

    A tutorial on DataBinding, the differences between all the options, why I would choose on over the other, the components that are truly required to get it to work in XAML, -AND- codebehind (for dynamically generated controls), and a deep discussion into the definitions of concepts that contain the word "context" in detail would be great…for us OLD programmers who are really having a tough time making the mental leap here.  Right now, it is not my highest priority to connect to AZURE…I’d just like to figure out simple CRUD on a single form on a single entity using databinding.  That would truly be awesome.  Thanks.

  9. Keoz says:

    You are my damn super hero!! oh yes  thanks!

Skip to main content