Windows Azure - Web 角色无法访问本地开发队列存储
我有一个在我的解决方案中的多个角色项目之间共享的类库。其中两个项目是 Web 角色和辅助角色。
他们每个人都有相同的配置设置:
<Setting name="QueueConnectionString" value="UseDevelopmentStorage=true" />
他们每个人都调用这个函数:
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));
}
当它在辅助角色中执行时,它可以正常工作,没有任何问题;我已确认队列消息的正确读取和写入。当它在 Web 角色中执行时,对queue.CreateifNotExist() 的调用会崩溃,并显示错误“响应在此上下文中不可用”。我已经尝试搜索有关可能导致此问题的原因的信息,但到目前为止我的搜索努力没有结果。如果我可以提供任何其他信息,请告诉我。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,经过大量工作后,我确定这是因为我是从 Global.asax Application_Start 中调用它的。
我将其移至我的 WebRole.cs OnStart() 函数中,并且它可以正常工作。
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.