Pro-Tip: Connecting To SharePoint Online / Office 365 from an Azure Web / Worker Role

1 February 2012

Today, I was tasked with debugging an issue someone at work had been having - we've built some stuff that needs to connect to a SharePoint Online instance from within an Azure Worker role, and whilst it worked locally, when it was run in the cloud, it continually caused the role to error out.

To connect, we're grabbing the claims-based cookies (for which you can read Chris Johnson's post about it) and using those to authenticate and it worked on the local DevFabric.

Here's the gotcha though - for your Azure Role, make sure you include the Microsoft.IdentityModel assembly that comes with WIF as a reference, and ensure it is set to Copy Local. The claims based stuff needs WIF to function, and doesn't come on Azure roles by default, though it may in the future...

But in the meantime, that's one more thing to check if you're getting the dreaded "CannotContactSite" ClientRequestException in the EnsureFormDigest() method call as part of the authentication procedure.

Thanks to these three great links that helped us piece it together!

Tags: Azure, exception, SharePoint Online, WIF

Add a Comment

No Comments