gpt4 book ai didi

c# - 从 Azure 上运行的辅助角色服务访问 Sharepoint

转载 作者:行者123 更新时间:2023-12-03 03:13:46 28 4
gpt4 key购买 nike

当另一个系统中的某些信息发生变化时,我需要更新 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 中运行的辅助角色,当我尝试从 Sharepoint 检索列表时,我发现出现了 403 Forbidden 异常(请参阅注释行“THIS LINE”)。
这是完全相同的代码,在本地运行正常,在 Azure 中运行会引发此异常!

注释:Office365ClaimsHelper 类来自 github
我已经尝试过this ,但这不是我的情况(我使用云服务而不是虚拟机)。
WorkerRole 的目标是 .Net 4.0(同样,这不是我的选择)

我尝试放置最重要的代码,但如果您需要更多内容,请告诉我,提前致谢!

最佳答案

所以这个问题的关键是当你点击Sharepoint O365时会得到403。 http://www.checkupdown.com/status/E403.html告诉我们 HTTP 403 错误表明(我的重点):

The Web server (running the Web site) thinks that the HTTP data stream sent by the client (e.g. your Web browser) was correct, but access to the resource identified by the URL is forbidden for some reason.

This indicates a fundamental access problem, which may be difficult to resolve because the HTTP protocol allows the Web server to give this response without providing any reason at all. So the 403 error is equivalent to a blanket 'NO' by the Web server - with no further discussion allowed.

尽管您的本地开发计算机上的代码(二进制文件)可能与云服务中的代码(二进制文件)相同,但您的配置可能不同。

因此,您能否检查云服务的 ServiceConfiguration.Local.cscfgServiceConfiguration.Cloud.cscfg 中是否具有相同的配置值,特别是 Sharepoint .UriSharepoint.ListName 值。

关于c# - 从 Azure 上运行的辅助角色服务访问 Sharepoint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32769245/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com