In the course of developing support for Microsoft Windows Azure for our Outlook Attachment Manager product, we searched hard for a good Windows Azure Storage services library. We did not find anything that can be used out-of-the-box. If you are developing a product using Windows Azure’s storage services only, we hope you can leverage our lessons learned.
Even though there is no good third-party library, we found a nice library in the Azure SDK. However, there are several problems with using that library directly. First of all, the Azure SDK only installs on Windows Vista or higher, i.e., it would not work on Windows XP. There are good reasons that it is only supported on Vista if you use Azure’s compute service. However, if you are only using the storage service, Window XP works just fine. To get around the problem, you need to change the Launch Conditions for the Azure SDK installation file. You can search Azure’s forum for full hacking instructions. But if you do not want to mess with it, we have extracted the library from the Azure SDK and you can simply download the original Microsoft Azure Storage Library from our developer page. In addition to the library, it also contains the sample code provided by Microsoft on how to use the storage library.
The Azure library requires Azure SDK and .NET 3.5 SP1 framework. Since we are only talking to Azure storage using REST protocol, there is no reason to require our customers to install the latest .NET framework. So we have to hack the library to remove these restrictions.
To remove the dependency on Azure SDK, we modified the StorageAccountInfo.cs file to comment out the reference to Microsoft.ServiceHosting.ServiceRuntime and RoleManager. They are used to check whether the program runs in the hosted Azure environment. Since our application always runs on the client’s machine, we can safely remove these references.
To remove the dependency on .NET 3.5 SP1, we removed TableStorage.cs from the project, since it references System.Data.Services.client which is part of .NET 3.5 SP1. We also have to remove several references to TableRetryWrapperException in BlobStorage.cs. If you do not want to mess with the code change, you can download the already modified Microsoft Azure Blob & Queue library for .NET 3.5 from our developer page.
We ended up using the .NET 3.5 library since we also use VSTO 2008 which requires .NET 3.5 anyhow. However, we have experimented with .NET 2.0. .NET 2.0 is only about 80MB installed, 1/4 the size of .NET 3.5. If you distribute software to people who may not have .NET installed, having .NET 2.0 will be a much lighter approach.
To make the library work under .NET 2.0, we had to make several changes. First, the library uses parameter-less System.Action<> delegate which is a new feature of .NET 3.5. We converted it to System.Action<T> with a dummy string parameter. Second, in invoking these actions, the library uses lambda expression which is a new feature since .NET 3.0. We converted them into anonymous methods. Third, we removed XML parsing for extended Table errors from Error.cs. They require System.Xml.Linq which only exists in .NET 3.5. Since we are not dealing with Tables, it is safe to remove them. Last, RestQueue.cs uses System.Linq.IEnumerable, which does not exist in .NET 2.0. It is easy to replace the functionality, but since we only use the Blob service, we did not venture further. You can download the working version of Microsoft Azure Blob library for .NET 2.0 from our developer page. RestQueue.cs and Queue.cs are removed from the project, but they remain in the source code, in case anyone want to make the last bit of modification to make it work for Queue.
We found the Microsoft library to be very well written. For example, it handles retries and you can specify your own retry policy. Our approach of modifying the Microsoft library worked well for us. It for sure beats writing the REST request from scratch.