【发布时间】:2015-12-22 12:32:37
【问题描述】:
当其他系统中的某些信息发生更改时,我需要更新 Sharepoint 上的某些信息。我这样做的方式(我没有选择,而是公司)是:
1.当其他系统发生事件时,我向Azure ServiceBus队列发送消息:
QueueClient queueClient = QueueClient.CreateFromConnectionString(connectionString, "authors");
BrokeredMessage message = new BrokeredMessage();
message.ContentType = "Authors";
message.Properties["FirstName"] = FirstName;
// set other properties
try {
queueClient.Send(message);
}
catch (Exception e) {
Logger.Error("Authors Windows Azure notification service fail.", e);
}
finally {
queueClient.Close();
}
这部分工作正常。
2.我创建了一个WorkerRole来读取ServiceBus,处理消息,并在Sharepoint中发布信息(我稍微简化了实际代码):
BrokeredMessage receivedMessage = Client.Receive(TimeSpan.FromSeconds(10));
if (receivedMessage != null && receivedMessage.ContentType == "Authors")
{
Uri uri = new Uri(CloudConfigurationManager.GetSetting("Sharepoint.Uri"));
Office365ClaimsHelper claimsHelper = new Office365ClaimsHelper(uri, CloudConfigurationManager.GetSetting("Sharepoint.User"), CloudConfigurationManager.GetSetting("Sharepoint.Password"));
using (ClientContext context = new ClientContext(uri))
{
context.ExecutingWebRequest += claimsHelper.clientContext_ExecutingWebRequest;
AuthorWrapper author = GetAuthorFromMessage(receivedMessage);
string title = CloudConfigurationManager.GetSetting("Sharepoint.ListName");
List authorsList = context.Web.Lists.GetByTitle(title);
context.Load(authorsList);
context.ExecuteQuery(); // THIS LINE
// do some other stuff, including adding the author to the list
}
receivedMessage.Complete();
}
当我在本地运行 WorkerRole(使用 Microsoft Azure 模拟器)时,一切正常,并且信息在 Sharepoint 中得到更新。
但是,当我在 Azure 中发布 WorkerRole 时,它不起作用(它从 ServiceBus 读取消息,但没有更新 Sharepoint)。我使用this 调试在 Azure 中运行的 Worker 角色,当我尝试从 Sharepoint 检索列表时发现 403 Forbidden 异常出现(请参阅注释行“THIS LINE”)。
这是完全相同的代码,在本地运行正常,在 Azure 中运行会引发此异常!
注意:Office365ClaimsHelper 类来自github
我已经尝试过this,但这不是我的情况(我使用云服务而不是虚拟机)。
WorkerRole 的目标是 .Net 4.0(同样,不是我的选择)
我尝试输入最重要的代码,但如果您需要更多信息,请告诉我,提前致谢!
【问题讨论】:
标签: c# azure sharepoint azure-worker-roles