Windows Azure Development
Small Business Starter Kit on Windows Azure
Whilst looking for a simple asp.net application I could “migrate” to Windows Azure, I stumbled upon the Small Business Starter Kit at the ASP.NET web site – http://www.asp.net/downloads/starter-kits/small-business/.
One of the features of the Small Business Starter Kit is the Provider Model. You can either use an SQL or XML data source. Bingo I thought. An XML data source! All I’d need to do with this is load the XML data from Windows Azure Blob storage instead of the file system and it would be running on Windows Azure!
Here is what I did (I assume you are using Visual Studio Web Developer Express & have the Windows Azure SDK & Tools installed):
- Downloaded the Starter Kit, and created a new Small Business Web Site.
- Created a new Cloud project, with a Web Role.
- Deleted the default.aspx & Web.config from the new web role
- Using windows explorer, copied the files from the web site created in step 1, to the folder for the web role created in step 2.
- Added the newly copied files to the project.
- Right clicked the Web Role project and selected Convert to Web Application (this fixes all the build properties, and creates the missing designer files etc.)
Now you can hit F5, and the site runs in Windows Azure. Magic. Clicking on Items, or People will give you errors, because we are trying to load the xml data from the file system. (Actually the error is because the files aren’t copied as part of the output. We could fix that, but really we want them in blob storage so they can be updated at runtime.)
The next step is to update the XML Provider to read the xml files from Blob storage, rather than the file system. Here are the steps I took:
- Added a reference to the storage client sdk sample.
- Added the required configuration to the servicedefinition.csdef and serviceconfiguration.cscfg files for AccountName, AccountSharedKey and BlobStorageEndpoint.
- Updated the ReadAndValidateXml method in the util.cs class to read from blob storage.
- Copied the xml files into blob storage. For this I used the Powershell provider for Windows Azure storage, which is shipped as source code in the SDK.
Hitting F5 runs the site, and reads the items, people etc. from blob storage.
Here is my serviceconfiguration.cscsf file:
<?xml version="1.0"?>
<ServiceConfiguration serviceName="starterbktest" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration">
<Role name="WebRole">
<Instances count="1"/>
<ConfigurationSettings>
<Setting name="AccountName" value="devstoreaccount1" />
<Setting name="AccountSharedKey" value="Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==" />
<Setting name="BlobStorageEndpoint" value="http://127.0.0.1:10000" />
</ConfigurationSettings>
</Role>
</ServiceConfiguration>
And here is my changed ReadAndValidateXml method:
public static DataSet ReadAndValidateXml(string xmlFilePath, string schemaFilePath)
{
xmlFilePath = Path.GetFileName(xmlFilePath).ToLower();
schemaFilePath = "schemas\\" + Path.GetFileName(schemaFilePath).ToLower();
DataSet dataSet = null;
BlobStorage store = BlobStorage.Create(StorageAccountInfo.GetDefaultBlobStorageAccountFromConfiguration());
BlobContainer container = store.GetBlobContainer("sbkit");
BlobContents xmlFileBlob = new BlobContents(new MemoryStream());
BlobContents xmlSchemaBlob = new BlobContents(new MemoryStream());
container.GetBlob(xmlFilePath, xmlFileBlob, false);
container.GetBlob(schemaFilePath, xmlSchemaBlob, false);
byte[] ook = xmlFileBlob.AsBytes();
byte[] schemaook = xmlSchemaBlob.AsBytes();
dataSet = new DataSet();
dataSet.ReadXmlSchema(new MemoryStream(schemaook));
dataSet.ReadXml(new MemoryStream(ook), XmlReadMode.IgnoreSchema);
return dataSet;
}
The first few lines rework the paths for the files. The rest is simple Blob storage code to read blobs.
For those with more than enough thiings to do already, here is the source code zip.
THIS POSTING IS PROVIDED "AS IS" WITH NO WARRANTIES, AND CONFERS NO RIGHTS
| Print article | This entry was posted by DavidAiken on February 9, 2009 at 7:45 am, and is filed under Windows Azure. Follow any responses to this post through RSS 2.0. Both comments and pings are currently closed. |
Comments are closed.
about 1 year ago
Excellent! I love seeing these simple samples. Thanks for contributing.