Please note: This blog is no longer active. My new blog is located at http://blog.timwheeler.io

Thursday, January 6, 2011

Azure Cloud Storage OutOfRange Error

I'm having an interesting time learning Azure and have found various issues, including Visual Studio 2010 hanging when the project is bound to Visual SourceSafe, random hang on project build and the AspProviders not working with development storage.

Here's what I found with the AspProviders issue:

The AspProviders from the Azure Samples errored on start up with an OutOfRange error . The providers didn't seem to work with developer storage. The providers didn't allow access to the dev storage addresses, likely due to http instead of https. To fix this I created a helper class that would get either the developer storage or the https address.

I had problems with TableStorageRoleProvider, TableStorageSessionStateProvider, TableStorageProfileProvider and TableStorageMembershipProvider.

The error I received was:

Microsoft.WindowsAzure.StorageClient.StorageClientException: Exception of type 'Microsoft.WindowsAzure.StorageClient.StorageClientException' was thrown. ---> System.Data.Services.Client.DataServiceQueryException: An error occurred while processing this request. ---> System.Data.Services.Client.DataServiceClientException: <?xml version="1.0" encoding="utf-8" standalone="yes"?><error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><code>OutOfRangeInput</code><message xml:lang="en-US">One of the request inputs is out of range.</message></error>

The client class I created:

Code Snippet
  1. /// <summary>
  2.     /// Class to create <see cref="CloudTableClient"/> or <see cref="CloudBloblClient"/> or <see cref="CloudQueueClient"/>
  3.     /// Works with developer storage at address "http://127.0.0.1" or https address.
  4.     /// </summary>
  5.     public static class StorageClient
  6.     {
  7.         
  8.         public static CloudTableClient GetCloudTableClient(string endpoint, string accountName, string sharedKey)
  9.         {
  10.             CloudStorageAccount account = GetAccount(endpoint, accountName, sharedKey);
  11.             return account.CreateCloudTableClient();
  12.         }
  13.         public static CloudTableClient GetCloudTableClient(string endpoint, StorageCredentialsAccountAndKey credentials)
  14.         {
  15.             CloudStorageAccount account = GetAccount(endpoint, credentials);
  16.             return account.CreateCloudTableClient();
  17.         }
  18.  
  19.         public static CloudBlobClient GetCloudBlobClient(string endpoint, string accountName, string sharedKey)
  20.         {
  21.             CloudStorageAccount account = GetAccount(endpoint, accountName, sharedKey);
  22.             return account.CreateCloudBlobClient();
  23.         }
  24.         public static CloudBlobClient GetCloudBlobClient(string endpoint, StorageCredentialsAccountAndKey credentials)
  25.         {
  26.             CloudStorageAccount account = GetAccount(endpoint, credentials);
  27.             return account.CreateCloudBlobClient();
  28.         }
  29.  
  30.         public static CloudQueueClient GetCloudQueueClient(string endpoint, string accountName, string sharedKey)
  31.         {
  32.             CloudStorageAccount account = GetAccount(endpoint, accountName, sharedKey);
  33.             return account.CreateCloudQueueClient();
  34.         }
  35.         public static CloudQueueClient GetCloudQueueClient(string endpoint, StorageCredentialsAccountAndKey credentials)
  36.         {
  37.             CloudStorageAccount account = GetAccount(endpoint, credentials);
  38.             return account.CreateCloudQueueClient();
  39.         }
  40.         
  41.         private static bool IsDevelopmentStorage(string endpoint)
  42.         {
  43.             const string devEndpoint = "http://127.0.0.1";
  44.             return (endpoint != null && endpoint.Length >= devEndpoint.Length &&
  45.                     devEndpoint.ToLower().Substring(0, devEndpoint.Length) == devEndpoint);
  46.         }
  47.         private static CloudStorageAccount GetAccount(string endpoint, StorageCredentialsAccountAndKey credentials)
  48.         {
  49.             CloudStorageAccount account = null;
  50.             if (IsDevelopmentStorage(endpoint))
  51.             {
  52.                 account = CloudStorageAccount.DevelopmentStorageAccount;
  53.             }
  54.             else
  55.             {
  56.                 account = new CloudStorageAccount(credentials, null, null, new Uri(endpoint));
  57.             }
  58.             return account;
  59.         }
  60.         private static CloudStorageAccount GetAccount(string endpoint, string accountName, string sharedKey)
  61.         {
  62.             CloudStorageAccount account = null;
  63.             if (IsDevelopmentStorage(endpoint))
  64.             {
  65.                 account = CloudStorageAccount.DevelopmentStorageAccount;
  66.             }
  67.             else
  68.             {
  69.                 var credentials = new StorageCredentialsAccountAndKey(accountName, sharedKey);
  70.                 account = new CloudStorageAccount(credentials, null, null, new Uri(endpoint));
  71.             }
  72.             return account;
  73.         }
  74.     }

I then changed the providers where they create the cloud client.

In the TableStorageRoleProvider I update the following line:

_tableStorage = new CloudTableClient(baseUri, info);

To:

_tableStorage = StorageClient.GetCloudTableClient(baseUri, accountName, sharedKey);

The other providers are similar.

That’s it!