I'm trying to develop multi-tier cloud application using Windows Azure. To store my data I've chosen Azure Storage Tables and Azure Storage Blobs.
Different tiers of my application use the same set of features, but in different way. e.g. they all must have access to blobs. I decided to make single class library to access Windows Azure Blob Storage, but I faced a 400 error.
When I connect to Blobs directly from my Worker Role it works fine, but when I call class from class library, it fails with 400 status code (Bad Request). Here is my code:
public class TestClass
{
public static void Test()
{
string s = CloudConfigurationManager.GetSetting("StorageCS");
CloudStorageAccount account = CloudStorageAccount.Parse
(
s
);
CloudBlobClient client = account.CreateCloudBlobClient();
CloudBlobContainer container =
client.GetContainerReference("mycontainer");
container.CreateIfNotExists(BlobContainerPublicAccessType.Blob);
}
}
This is a test class that just tries to access blob container. When I use this class inside my worker role, it works fine. If I reference this worker role from another worker role and use this class inside second role it works, but if i move this class to external class library, it fails. Exception is thrown on line 'container.CreateIfNotExists(BlobContainerPublicAccessType.Blob);' This is a StorageException, with '400. Bad Request' message.
I'm using Azure Storage Emulator. Using debugger, I've checked that there is corrent connection string ("UseDevelopmentStorage=true") given to CloudStorageAccount.Parse method, no matter how (directly, form class library, from other worker role) class is used. It seems that one cannot access Azure Storage using class library?