2
votes

I have a class library that is shared between multiple Role projects in my solution. Two of these projects are a Web Role and a Worker Role.

They each have the same Configuration Setting:

<Setting name="QueueConnectionString" value="UseDevelopmentStorage=true" />

each of them is making a call to this function:

public static void AddMessage(string Message)
    {
        var account = CloudStorageAccount.DevelopmentStorageAccount;
        ServicePoint queueServicePoint = ServicePointManager.FindServicePoint(account.QueueEndpoint);
        queueServicePoint.UseNagleAlgorithm = false;
        var client = account.CreateCloudQueueClient();
        var queue = client.GetQueueReference(DefaultRoleInstanceQueueName);
        queue.CreateIfNotExist();
        queue.AddMessage(new CloudQueueMessage(Message));
 }

When this executes in the Worker Role, it works without any issues; I've confirmed proper reads and writes of Queue messages. When it executes in the Web Roles, the call to queue.CreateifNotExist() crashes with the error "Response is not available in this context". I've tried searching for information on what could be causing this but so far my search efforts have been fruitless. Please let me know if there's any additional information I can include.

1

1 Answers

6
votes

ok, so after a lot more work, I determined that it was because i was calling it from within the Global.asax Application_Start.

I moved this to my WebRole.cs OnStart() function and it works properly.