Saturday, April 20, 2013

SharePoint2013: Shopping Cart Provider hosted app prototype

Scenario: How to develop a shopping cart provider hosted app prototype using managed CSOM

Solution: Create a Provider Hosted App using "App for SharePoint2013" template

Add the following code in the remote web (web application) projects home\landing page (.aspx) within the "body\form" section.

Add the following code in remote webs home\landing page code behind.

Call the "RetrieveWithCSOM" function in Page_Load, passing it the accessToken.

The sample shopping cart prototype app UI looks like below
 
Note: If your Remote webapplication is located outside the firewall , you may see 401 error while remote webapplication is trying to talk back to SharePoint, in this scenario use Cross-domain library to talk back to SharePoint.