AspAlliance.com LogoASPAlliance: Articles, reviews, and samples for .NET Developers
URL:
http://aspalliance.com/articleViewer.aspx?aId=1841&pId=-1
Azure Basics - Say 'Hello' to the Cloud
page
by Shaun Eutsey
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 32257/ 75

Introduction

Every once in a while something happens in the technology industry that is pretty cool.  OK, let's face it, cool stuff is released all of the time, that's why we do what we do, right?  I find it fascinating to be on the bleeding edge of things.  Unfortunately, like most of you, I work at a place that doesn't adopt new technologies until they are proven being the only reasonable thing to do in an enterprise.  With that I have to pick and choose the technologies to which I will devote my after hours time.  The latest one that I have decided to devote time to is Windows Azure.  In this article I am not going to go over any of the more complicated features of Azure.  I will walk through how to download the SDK's and Toolkits you will need and the hoops that you need to jump through to get some actual cloud space in which to host your project.  I will then show a quick and simple application that can be used to show how to upload an application to the cloud.

Disclaimer

The important thing to remember before you start developing in Azure is that this is still pre-beta.  There are some issues you may run into.  There is a "big" one that needs to be mentioned.

I run Windows 7 as my main OS on my Laptop.  I am a Windows 7 fanboy, sue me.  However, the risk of using a beta OS and a pre-beta framework is the potential that the two are not compatible.  Well, risk assessed and confirmed.  The two are not compatible on the beta of Windows 7.  When Windows 7 RC 1 is released, I have it on good authority (Thank you Steve Marx); the compatibility issues will be resolved.  To overcome this issue, I set up a Windows Server 2008 Virtual Machine (Thank you Heroes Happen Here!).

Prerequisites

Before you can start developing a project in Azure, there are a few steps you must take first.  Fortunately, most of the things can be grabbed by going to www.Azure.com and clicking on the Try It now button.

The first thing that the site lists is to register for the Azure services.  I don't think this should be your first step, but it is something that we'll get to a little later.  However, there are a couple of downloads that you'll need to grab.  You'll need the Windows Azure SDK, Windows Azure Tools for Microsoft Visual Studio and Microsoft .NET Services SDK.  If you want to include the Live Framework in your application you'll need to grab the Live Framework Documentation and Resources.

Install these bits and breath a sigh of relief, you are about to start your journey into Azure!

First Steps - Creating a project.

Of course the first thing you must do is create your project.  The steps need to create the project are pretty standard, but I will walk through it from the beginning.

Once you've clicked create, you'll need to know what type of project you want to work on.  For our purposes here, pretty much a "Hello World!" type of application, we'll select Web Cloud Service.  If we wanted to have data interaction with our website we would select the Web and Worker Cloud Service project type.  However, we are only doing a "Hello World!" app, so we'll keep it to just Web Cloud Service.

Coding for Azure

Now, let's break down the solution that was just created. 

The first project in the solution is the HelloAzure project, this is made up of:

·         Roles Directory - Contains a list of the Roles included in the solution.  If there were a worker role another role file would be in the directory called HelloAzure_WorkerRole.

·         Roles\HelloAzure_WebRole - Ties HelloAzure to the HelloAzure_WebRole Project

·         ServiceConfiguration.cscfg - Sets the configuration settings for the project (If you are using table, blog or queue storage)

·         ServiceDefinition.csdef - This file defines the settings used in the .cscfg file.

This project is the main project with the hooks to Azure.  When you publish this project it creates the files that need to be uploaded to Azure for deployment.

The next project in the solution is the HelloAzure_WebRole.  This is where the web user interface will reside. 

Now, we want to actually do something in Azure.  Like I said before, this is going to be very basic; something to just get you acclimated to the Azure environment.

Open up default.asp to get started.  We'll need two controls for the purposes of this demo, a Label and a Button.

<asp:Label id="lblMessage" runat="server" text="" /><br />
<asp:Button id="btnSubmit" runat="server" text="Submit" />

Simple enough, now let us add a little functionality to the example.

First, when you get into the code behind, notice the references at the top, in VB you'll have the following:

Imports Microsoft.ServiceHosting.ServiceRuntime

Now let us take a look at the click subroutine.

Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
   Dim dt as DateTime = Now
   Dim sb As New StringBuilder("Hello, Azure, the Date is ")
   sb.Append(dt.ToShortDateString)
   sb.Append(" and the time is ")
   sb.Append(dt.ToLongTimeString)
 
   lblMessage.Text = sb.ToString
End Sub

I used a string builder to look cool, but it really is overkill for what I am trying to accomplish.

We can now run this in the development fabric by hitting F5.

After it builds and starts the development fabric you are presented with a button called submit.  Due to the fact that we are all super intuitive and are compelled to click buttons called submit, click the button.

You will then see, something like:

Click it again, it updates, simple.  Looks like a regular, normal ASP.Net website.  That is the goal though, to host applications in the cloud.

The challenges of Azure come into being when you start working with Web Services and the storage mediums.

I'll enumerate some of the issues that my co-workers and I have run into at the end of the article.  What needs to be remembered is that Azure is in CTP.  The issues we've run into this week may not be their next week, so take all criticism for what it is intended, to  expose current issues that need worked on by the Azure team, not bashing of the technology.

Get a Seat on Azure

At this point we want to move our new app to the real cloud environment.  If you haven't already gone through the steps to get your place in the cloud, once again, go to http://www.azure.com and click Try It Now (see top of the article for a screenshot of the page).

Now, click Register for Azure Services.

Sign into your Live account, if you're not already, then fill out the form, and the waiting begins.

You will then have to wait for your access keys to get to you, which could take a couple of days.

Azure Cloud Deployment

Once you get your account information and your Azure Services Account set up, you can now publish the application to the cloud.

You'll need to right click the HelloAzure project and select Publish.

This builds the application and outputs two files to the bin directory, HelloAzure.cspkg and HelloAzure.cscfg.  These file will need be referenced from your cloud dashboard, which will pop up automatically when the application is done publishing.

For deployment to the cloud, now that the Azure Services Development Portal is open is to simply click deploy!

Now, you'll be asked for the two files that were created during the deployment as well as a label.

After filling in everything, click Deploy.

At that point the portal will go out to your PC, and "suck up" the application into the cloud.  This takes a little time, but it puts everything out in the cloud, which, for all intents and purposes, can be anywhere.  The application will be uploaded to the staging area.  To deploy to production, just hit the  button.

And there you go.  You can now bring up your cloud application by navigating to *AppName*.cloudapp.net.

Issues

Here is a list of the issues that we've run into with Azure as of the March 2009 CTP:

1.    WCF Web Services, when created in Azure, do not create all of the correct plumbing needed to run correctly.  You can find a good work around in the "Building Windows Azure Service" hands on lab included in the Windows Azure Training Toolkit.

2.    Working with Azure Table storage in WCF (and Azure in general) is cumbersome.  If you can, get a seat in the SQL Data Services and use them.  Much easier to do real work.

3.    Logging, so you know what your development cloud is doing, doesn't work after you first run the project in development.  The solution to this one is simple, but annoying.  You must stop the development fabric after every run if you wish to see the logging.

These are the bigger issues we have run into, and they are all outside of the scope of this article, but the need mentioned, so that no one goes into more advanced functionality blind.

Conclusion

In conclusion, I would say that though Azure is not ready for prime time (as of the March 2009 CTP) the potential that it packs is impressive.  The fact that you can develop for the cloud using .Net is one thing, that they've opened it up to PHP sends it over the top.  I'm not a PHP developer, my exposure to it as a language is limited, however, I think that including it into the Azure fabric is a brilliant move and will lead to greater things for the platform. 

Also, they are introducing many services to Azure, such as SQL Data Services, Office Services and even Dynamics Services.  These may not all be available for consumption yet, but they are on the way.  It is things like this that are going to push Azure over the top in the war for the cloud, in my opinion.


Product Spotlight
Product Spotlight 

©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-25 7:08:25 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search