Windows Azure Guest Book – Refactored

 

Due to the namespace change of the Windows Azure SDK, a number of the Windows Azure Platform Training Kit projects were broken.  As a part of the Guelph Coffee and Code Windows Azure Technology Focus Panel, I have refactored this Project in order to launch it into the cloud as one of my Azure Deployments.  If you haven’t already, you may want to visit my previous blog post entitled Moving from the ‘ServiceHosting’ to ‘WindowsAzure’ Namespace.  In the previous post I reviewed some of the changes in the classes that were contained in the Windows.ServiceHosting.ServiceRuntime namespace.

Another change in the Azure SDK is in the RoleEntryPoint Class.  The Start method which originally had a void return type has been changed to OnStart and returns a boolean value.  A method called GetHealthStatus() which returned a RoleStatus enum value, was removed.

I am still looking for an alternative to one of the most useful debugging features of Windows Azure to date. RoleManager.WriteToLog() was not replaced in the RoleEnvironment class.  This was one of the only gateways into writing out some error information without the use of the Storage Services or a SQL Azure database.

All of the mentioned Changes to the SDK were the issues behind the Windows Azure Guest Book not functioning from the November Platform Training Kit. You can go and make these changes yourself if you would like, or you can download the refactored version.

Happy Coding!

Moving from the ‘ServiceHosting’ to ‘WindowsAzure’ Namespace

 

Being part of a Technology Focus Panel for Windows Azure was quite a rewarding experience for me. I rarely get to work with emerging technology, which is one of the main reasons why I started Guelph Coffee and Code.  We’re getting down to the wire of launching 20 applications up to the cloud, and I’ve been putting in some extra time ensuring that we reach our goal. I’m working on compiling an application as I write this post, but I thought I would share some of the knowledge I’ve gained while Debugging the ‘Windows Azure Guest Book using Tables’ application found in the November 2009 CTP Platform Kit part of the Windows Azure Get Started steps.

The solution has a reference to the Microsoft.ServiceHosting.ServiceRuntime namespace that has recently changed its name after the Microsoft PDC Conference. If you are having a hard time compiling some of the projects it will most likely have something to do with the name change. Please note that the Microsoft.ServiceHosting.ServiceRuntime has been changed to Microsoft.WindowsAzure.ServiceRuntime which is more suiting as the platform is called Windows Azure. Not only has the namespace been changed but there are a number of Classes that have been refactored as well.

The RoleManager class has been changed to RoleEnvironment along with some of the members of the class. Let’s take a look at them in Context.

RoleManager: [Note: These are Snippets from the StorageClient Project, File: StorageAccountInfo.cs]

 // settings in the csc file overload settings in Web.config
            if (RoleManager.IsRoleManagerRunning)
            {
                string cscRet = TryGetConfigurationSetting(configurationSetting);
                if (!string.IsNullOrEmpty(cscRet))
                {
                    ret = cscRet;
                }

 

RoleEnvironment:

 // settings in the csc file overload settings in Web.config
            if (RoleEnvironment.IsAvailable)
            {
                string cscRet = TryGetConfigurationSetting(configurationSetting);
                if (!string.IsNullOrEmpty(cscRet))
                {
                    ret = cscRet;
                }

 

As you can see from the snippet above (bolded text) that RoleManager.IsRoleManagerRunning as been replaced by RoleEnvironment.IsAvailable.

Another change was found when accessing the Role configuration file.  The method RoleManager.GetConfigurationSetting was replaced by RoleEnvironment.GetConfigurationSettingValue.

RoleManager:

 private static string TryGetConfigurationSetting(string configName)
        {
            string ret = null;
            try
            {
                ret = RoleManager.GetConfigurationSetting(configName);
            }
            catch (RoleManagerException)
            {
                return null;
            }
            return ret;
        }

 

RoleEnvironment:

 private static string TryGetConfigurationSetting(string configName)
        {
            string ret = null;
            try
            {
                ret = RoleEnvironment.GetConfigurationSettingValue(configName);
            }
            catch (RoleEnvironmentException)
            {
                return null;
            }
            return ret;
        }

 

Another thing to note from the snippets above is the RoleManagerException has been changed to RoleEnvironmentException, which shouldn’t come as too big of a surprise.

In order to find these code changes I used the RedGate .NET Reflector Tool, and compared the library Microsoft.ServiceHosting.ServiceRuntime.dll for similarities to the library Microsoft.WindowsAzure.ServiceRuntime.dll.

Making data rain down from the Cloud with SQL Azure.

Hopefully you’ve had the chance to get a token [Check for a token here] to check out Microsoft’s Upcoming Cloud computing Platform Windows Azure. I’ll be posting some more information about Windows Azure in the coming weeks, but while i am creating a new website for Guelph Coffee and Code I thought I would bring you some information on connecting to SQL Azure in order to get your database up into the cloud.

Even though it is possible to connect to a database using SQL Server 2008, I’d suggest getting the Nov CTP for SQL Server 2008R2.  Just incase you don’t want to download a CTP here’s a hint as to how you can connect to your database with SQL Server 2008. The main reason I suggest SQL Server 2008 R2 is due to the fact that the Object Explorer of the current version of SQL Server is not compatible with SQL Azure.

Oh, I see you took my hint and downloaded R2, excellent choice. Now that you have your SQL Server Management Studio set up, lets take a look at some of the configurations that we will have to do in SQL Azure in order to connect to our database. [At the time of this blog post SQL Azure was available only to those who requested a token to access it. This post assumes you have access to SQL Azure.]  Here are the steps to take to get to the SQL Azure Cloud Configuration Console.

You should now be in an area that contains an interface much like this one:

Database_Console

As you see I’ve already Created a Database, it’s a very simple process where you define a name and a size [1GB or 10GB] and click on OK to create it.  In order to allow your Azure applications or to Manage your database using your SQL Server Management Studio you will have to allow connections through the Firewall, to change the firewall settings click on the ‘Firewall Settings’ tab.

Database_Firewall_AllowMSServices

In order for your Azure applications to be able to connect to your SQL Azure Database you will need to check the ‘Allow Microsoft Services access to this server’ checkbox. This adds the ‘MicrosoftServices’ Definition in the Rules grid.  If you don’t intend on using the SQL Azure database with a Windows Azure Application, keep the box unchecked.  To Allow you to access SQL Azure using SSMS you will have to Add a Rule.

Database_Firewall_AllowIPRange

The SQL Azure team did an excellent job making the Rules to be simple to configure.  Enter a name, which is a Label to Identify the IP Range you are allowing to connect.  Then specify an IP Range that you wish to allow access to this database.  You’ll notice that the application displays your IP Address, so if you only wish to add your IP simply copy and paste the IP address into both the Start and End textboxes. Then Click Submit to Save the changes. Repeat this step if you would like to be able to connect to your SQL Azure database from Multiple locations (Work, and Home).

One last piece of information you’ll need from the Azure Services site is the Connection String for your new Database. To get the Connection String, Navigate back to the Databases Tab. Select your new database from the list and click on the ‘Connection Strings’ button.

Database_ConnectionString

From here you can either select the entire Connection String and Copy using the Right Click context menu, or click on the ‘Copy to clipboard’ link (which may cause a Security pop-up in your browser) [Note: Choose the appropriate Connection String for your Application. I have only tested the ADO.NET Connection String in SSMS].  Paste your Connection String somewhere it is easy to work with, I prefer using ‘Sticky Notes’ a feature of Windows 7, but you can use notepad if you’re more inclined to do so.

If you haven’t done so Already, Fire up your installation for SQL Server 2008 R2 Management Studio. [The SQL Server instance in the cloud uses the TCP port 1433 so you will have to make sure that your Firewall will allow outbound traffic on TCP port 1433.]  As you normally would, Select Connect to Server from the Object Explorer.

SSMS_ConnectToServer

Fill out the Server name, Login and Password information [Note: The Server name, and login are contained in your Connection String that you pasted safely into Sticky Notes or Notepad.]  Your password you would have set while accessing the SQL Azure Menu for the first time. At this point it gets a little bit different than your typical connection to the database. If you were to connect now, you will only have access to the ‘master’ database which you do not have the ability to add tables to, not to mention you’ve created a nice new database to house your data for your current application. Here’s the trick to make sure you connect to the proper database on your SQL Azure account:

  • Click on Options at the bottom of the Connect to Server Screen.
  • Select the Additional Connection Parameter Tab
  • Paste in your trusty connection string [waiting idly by in Sticky Notes]
  • Change the password in the Connection String from myPassword to your actual SQL Azure password
  • Hit the Connect button to Connect to the database.

Now that we’re up and running lets add a few tables.  Being a .NET Developer myself I know that one of the existing .NET Features I’m going to want to leverage will be the ASP.NET Membership Provider. After giving the command-line utility a try, I found out that SQL Azure does not support a number of Commands that are contained in the Utility.  This includes use [cannot select other databases in the cloud], GRANT your login cannot GRANT or DENY privileges on the tables or stored procedures, nor is it able to Query against the master table.

No I wouldn’t bring this up just to let you down, here is a work around. Open the Visual Studio 20008 Command Prompt, and type the following:

aspnet_regsql.exe -A mpr -sqlexportonly <filePath>

-A: Application Services Options

  • P – Profiles
  • M – Membership
  • R – Role Manager

Then Obviously replace <filePath> with a Path where you can Save the SQL Output like “C:\SQL\ASP_NET_MemberShip_Tables.sql”.

This will allow you to run the SQL file against the database in the SSMS Query window. It will throw warnings about the invalid keywords but the tables and stored procedures get created regardless.

I wish you luck with your Deployments to Windows Azure, Stay Tuned for more blog posts on Developing on the Windows Azure Platform.

 

Floating up into the Windows Azure Cloud

Microsoft’s Cloud Computing platform Windows Azure is nearing it’s debut as it will be launching publicly in January.  If you would like to get a head start head on over to the Windows Azure Getting Started page.

My community group Guelph Coffee and Code [coming soon: www.guelphcoffeeandcode.org] was invited to test out the Windows Azure Platform.  Our mission is to launch 20 applications into the cloud by the end of November. I have launched 2 applications thus far, the first was the my to do application from the Windows Azure Platform Training Kit, next I headed off to Code Plex and found a Windows Azure Sudoku Application [See my deployment here].

The Sudoku application Leverages ASP.NET, Silverlight, and WCF Web Services.  During the course of the video below, I will run you through publishing the application and deploying it into the cloud. The Sudoku application doesn’t require a Storage Service, but I went through the steps of setting one up just incase it would be helpful in your deployments.

I hope you enjoy the video, and enjoy your experiences floating in the cloud.

Notice: The video was hosted on a now deprecated service and is no longer available.

[Screen cast was recorded using TechSmith Camtasia Studio]

Windows Mobile Dev Camp: Toronto is Tomorrow!

It is with deep regret that I am unable to make it out to the Windows Mobile Development Camp.  I have just started a new position at RKD Web Studios just over a month ago, and am unable to take time off due to my probationary period.

However, that doesn’t mean that anyone else out there has to miss out and with great prizes like (3) Call of Duty: Modern Warfare 2 Games, (1) Modern Warfare 2 Limited Edition Xbox360, or (1) Pair of Modern Warfare branded Night vision goggles I would be heading on over to the registration page right now! [What are you waiting for?]

If you are attending, make sure to soak up as much information as possible, If you could, please share your notes. Contact me on Twitter my Username is SyntaxC4.  I would love to see any notes, presentations or sample applications that have been made at WinMoDevCamp!

 So for you die hard readers, head over to the Registration page now!

 *** UPDATE ***

Anthony Bartolo was nice enough to pass along todays agenda, which includes a link to the live stream for those of us that couldn’t make it today, myself included. Please check out the Agenda to see if you would like to tune into the Windows Mobile Development Camp Sessions.

Here’s the Agenda, WinMoDevCamp Event Agenda.pdf (104.36 kb)

The Event starts at 1pm so don’t miss out!

CTTDNUG Presentation: MVVM in Silverlight

You may or may not be aware but I am currently the speaker coordinator for the Canadian Technology Triangle .Net User Group [CTTDNUG]. I have been finding presenters since June 2009. On occasion, it is difficult to find a speaker due to the busy seasons when there are a lot of professional development conferences going on.  We turn our search for presenters inward to our Organization Committee, or to people within the Group.

With the Microsoft Tech Days Conference series crossing Canada this year, there has been a few occasions where the organization committee had to step up to present.  In September, Dave Totzke from Object Sharp did a presentation on Silverlight 3. Unfortunately I missed Dave’s presentation, but I’ll see if I can get it off of him to post.  As a follow up to Dave’s presentation, on October 28th I hit the stage with a presentation on MVVM, a design pattern for making Silverlight applications.

In order for the group to be able to benefit from the lecture, I am blogging to share my presentation slides and Sample code.  Hopefully you’ve read my last post ’Podcast Shout-out’, as the concept of my demo was borrowed from a Screen-Cast on Craig Shoemaker’s Pixel 8 blog.

Just incase you would like to read up on M-V-VM a bit more here are some of the resources I used to learn it.

At the time of this posting it is shortly before PDC, John Papa is in the works of creating a blog post comparing the different implementations of MVVM. I will be sure to update this post once his blog posting comes out.

Here’s my presentation for those of you that wish to check it out:

Demo   Slides

Enjoy!