2
votes

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?

1
No, for sure you can access Azure. When you use the emulator, it used the development storage, it is at local. Do you have a storage account on Azure?Matt

1 Answers

6
votes

Please check the version of storage client library in your class library project. In all likelihood it is version 3.0.0.0. If that's the case, then please note that currently version 3.0.0.0 of storage client library is not compatible with storage emulator (development storage). This is because the library makes use of latest version of storage REST API and the emulator only supports a version before that. The compatibility issue is highlighted in storage team blog here: http://blogs.msdn.com/b/windowsazurestorage/archive/2013/11/27/windows-azure-storage-release-introducing-cors-json-minute-metrics-and-more.aspx (Please read "Storage Emulator Guidance" section towards the end of the post)

My recommendation would be to downgrade storage client library to previous version (2.1.0.4). You can install this version via Nuget Package Manager console and typing the following command there: Install-Package WindowsAzure.Storage -Version 2.1.0.4.