从 Azure 上运行的辅助角色服务访问 Sharepoint [英] Access Sharepoint from a Worker role service running on Azure

查看:65
本文介绍了从 Azure 上运行的辅助角色服务访问 Sharepoint的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当其他系统中的某些信息发生变化时,我需要更新 Sharepoint 上的某些信息.我这样做的方式(我没有选择,而是选择公司)是:
1. 当其他系统中发生事件时,我向 Azure ServiceBus 队列发送消息:

I need to update some information on Sharepoint when some information changes in another system. The way I'm doing this (I didn't get to choose, but rather the company) is:
1. When the event occurs in the other system, I send a message to an Azure ServiceBus queue:

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中(我稍微简化了实际代码):

This part works fine.
2. I created a WorkerRole to read the ServiceBus, process the message, and post the information in Sharepoint (I simplified the actual code a bit):

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 异常出现(请参阅注释行此行").
这是完全相同的代码,在本地运行可以正常工作,在 Azure 中运行会引发此异常!

When I ran the WorkerRole locally (using Microsoft Azure Emulator), everything worked perfectly and the information got updated in Sharepoint.
However, when I Published the WorkerRole in Azure, it didn't work (it read the message from the ServiceBus, but didn't update Sharepoint). I used this to debug the the Worker role that's running in Azure, and I found that a 403 Forbidden exception rose when I tried to retrieve the list from Sharepoint (see commented line "THIS LINE").
It's the EXACT SAME CODE, running locally works fine, running in Azure raises this exception!

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

Notes: the Office365ClaimsHelper class is from github
I already tried this, but it's not my case (I use Cloud Service not Virtual Machine).
The WorkerRole is targeting .Net 4.0 (again, not my choice)

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

I tried to put the most significant code, but if you need something more let me know, thanks in advance!

推荐答案

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

So the crux of this problem is that you get a 403 when hitting Sharepoint O365. http://www.checkupdown.com/status/E403.html tells us that a HTTP 403 error indicates (my emphasis):

Web 服务器(运行网站)认为 HTTP 数据流由客户端发送(例如您的 Web 浏览器)是正确的,但对 URL 标识的资源的访问是由于某种原因被禁止.

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.

这表明存在基本访问问题,这可能很难解析,因为 HTTP 协议允许 Web 服务器给出这个完全不提供任何理由的回应.所以403错误是相当于网络服务器的一揽子否" - 没有进一步允许讨论.

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.

尽管您的本地开发机器和云服务中的代码(二进制文件)可能相同,您的配置可能不相同.

Although your code (binaries) might be the same on your local dev machine and in the Cloud Service, your configuration might not be the same.

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

Can you therefore check that you have the same configuration values in your Cloud Service's ServiceConfiguration.Local.cscfg and ServiceConfiguration.Cloud.cscfg, specifically the Sharepoint.Uri and Sharepoint.ListName values.

这篇关于从 Azure 上运行的辅助角色服务访问 Sharepoint的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆