【问题标题】:Access Sharepoint from a Worker role service running on Azure从 Azure 上运行的辅助角色服务访问 Sharepoint
【发布时间】: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


    【解决方案1】:

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

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

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

    虽然您的代码(二进制文件)在本地开发机器和云服务中可能相同,但您的配置可能不一样

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

    【讨论】:

    • 感谢您的回答!我投了赞成票,但没有打勾,因为问题是另一回事。我从 Azure 中删除了该服务,更改了所有引用 Copy Local = true (不确定这是否正确,我将对此提出一个新问题),在部署之前打包 WorkerRole 并且(仍然不确定为什么)在那里工作...
    • 啊,神秘的“我用棍子戳它”,现在它起作用了!
    • 哈哈正好!仅供参考,这是我提到的问题stackoverflow.com/questions/32785383/…
    猜你喜欢
    • 1970-01-01
    • 2011-08-21
    • 1970-01-01
    • 2012-11-20
    • 2015-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多