-1

I am trying to use MS Windows Azure queue in windows service to read messages. I am getting below error while creating queuereference,

Exception Info: Microsoft.WindowsAzure.Storage.StorageException at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[[System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](Microsoft.WindowsAzure.Storage.Core.Executor.RESTCommand`1, Microsoft.WindowsAzure.Storage.RetryPolicies.IRetryPolicy, Microsoft.WindowsAzure.Storage.OperationContext) at Microsoft.WindowsAzure.Storage.Queue.CloudQueue.CreateIfNotExists(Microsoft.WindowsAzure.Storage.Queue.QueueRequestOptions, Microsoft.WindowsAzure.Storage.OperationContext)

But whereas the same piece of code work as console app.

CloudStorageAccount storageAccount = CloudStorageAccount.Parse(GetQueueSource);
        CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
        CloudQueue queue = queueClient.GetQueueReference(QueueRef);
        queue.CreateIfNotExists(); //getting error at this point
        return queue;
Jegan
  • 139
  • 1
  • 8

1 Answers1

0

I am trying to use MS Windows Azure queue in windows service to read messages. I am getting below error while creating queuereference

I create a simple Windows Service application and put the code in OnStart method, like this.

protected override void OnStart(string[] args)
{
    CloudStorageAccount storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName={mystorageaccountname};AccountKey={account key}");

    CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();

    CloudQueue queue = queueClient.GetQueueReference("myqueue");

    queue.CreateIfNotExists();

    CloudQueueMessage mes = new CloudQueueMessage("windows service mes");
    queue.AddMessage(mes);
}

The queue could be created and message could be added to this queue when the service starts running on my side. I am using WindowsAzure.Storage v8.1.0 and .NET framework 4.5.

<package id="WindowsAzure.Storage" version="8.1.0" targetFramework="net45" />

You could create a new Windows Service application and do same test with my code to check if you could operate queue message without error. Besides, please make sure if the queue name confirm to these rules.

Fei Han
  • 26,415
  • 1
  • 30
  • 41