Windows Azure - Web 角色无法访问本地开发队列存储

发布于 2024-09-17 19:35:44 字数 915 浏览 2 评论 0原文

我有一个在我的解决方案中的多个角色项目之间共享的类库。其中两个项目是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傲性难收 2024-09-24 19:35:44

好的,经过大量工作后,我确定这是因为我是从 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文