By Daniel Du
In part 1 and part 2, I created a RESTful service, and rendered command usage statistics into a magic ball with three.js. It runs fine on my laptop, the data is stored in SQL Express. In this post, I would like to move it up to cloud, migrate this local asp.net web application to Windows Azure.
Actually it is pretty easy to migrate an existing ASP.NET web application to windows azure cloud. If you are using sessions in asp.net to maintain states, then you need to be careful, you may want to save your session into database or AppFabric. Fortunately my service only handles stateless request in REST way, so I would omit this part.
Firstly add a project into the solution, select “Windows Azure Cloud Service” template:
In following page just click “OK” without adding any new roles, as we are going to add the existing asp.net application as web role latter.
A new cloud service project will be added into solution. Now right click Roles, Add –> Web Role Project in solution, and select the asp.net web application to add it to cloud project as web role.
You can edit the properties of this role if you want to, for example, change the instance count or VM size. I did some test on Azure Emulator, everything works fine.
Currently our database is still on my laptop, now it is time to move it up to cloud. For simplicity, I use SQL Azure. Firstly I need to login to Windows Azure Management console to create a SQL Azure. New –> Data Services –> SQL DATABASE –> CUSTOM CREATE.
Give a database name, you can also create a new SQL database server if you have not done this before.
Please specify the same region as your service( we will create the service latter), anyway, it is a good idea to select a region close to your customers to get better performance. I am using East Asia here.
Once the SQL database is created, we can migrate our database from SQL Express to SQL Azure. Actually I can connect to the SQL Azure using SQL Server 2008 management studio from my laptop. But wait, we need to set up Windows Azure firewall rule from our IP address first. Click the database name in Azure management console you will get a page like below, which makes it very simple to set the firewall rule just by a clicking.
If you read part 1, you will remember, we are connecting to the local SQL Express in web.config, now I would like to connect to SQL Azure directly. the connection string can by found by clicking “View SQL Database connection strings”:
Copy this connection string to the web.config , input your password and compile:
<!--<add name="AcadCommandViewerContext" connectionString="Data Source=.\SQLEXPRESS;
Initial Catalog=AcadCommandViewerContext; Integrated Security=True;
<add name="AcadCommandViewerContext" connectionString="Data Source=tcp:qmhqjrmav7.database.windows.net,1433;
Initial Catalog=acadcmdviewer;User Id=<sql server user id>;Password=<input your password>;"
With Entity Framework, I can populate the initial data in SQL Azure in the same way as I did on SQL Express. Go to Package Manager Console from Tools—> Library Package Manager, run Update-Database command in package Manager Console to create the database and test data.
Now I am ready to publish/deploy my service to cloud. A simple way is to use the wizard of Visual Studio. Right click the cloud project and select Publish:
I have imported my MSDN subscription credentials following the hyper-link on wizard.
Create a new cloud service, and select the same location as the SQL Azure.
You can also check other settings in this wizard or just leave it as default. Click Publish when you are ready, a few minutes later, your service will be running on cloud!
OK, next post will talk about the implementation of AutoCAD plugin. Thanks you and have a good day!
You can follow this conversation by subscribing to the comment feed for this post.