• Save
Rest API and Client OM for Developer
Upcoming SlideShare
Loading in...5
×
 

Rest API and Client OM for Developer

on

  • 1,758 views

Presented at SharePoint TechFest on May 17, 2012. All rights reserved.

Presented at SharePoint TechFest on May 17, 2012. All rights reserved.

Statistics

Views

Total Views
1,758
Views on SlideShare
1,758
Embed Views
0

Actions

Likes
0
Downloads
2
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • ryadav@microsoft.com
  • http://msdn.microsoft.com/en-us/library/ee857094.aspxhttp://msdn.microsoft.com/en-us/library/hh185006
  • listdata.svc/Employees?$orderby=Fullnamelistdata.svc/Employees?$filter=JobTitleeq 'SDE'listdata.svc/Employees?$select=Fullname,JobTitlelistdata.svc/Employees?$top=10&$skip=30listdata.svc/Employees?$expand=Project

Rest API and Client OM for Developer Rest API and Client OM for Developer Presentation Transcript

  • REST API and Client Object Model for SharePoint DeveloperRam YadavSr ConsultantMicrosoft Corp.MCM : SharePoint 2007/2010
  • Agenda Overview of accessing Data in SharePoint Client Object Model  .NET Client Object Model  JavaScript and Client Object Model REST & WCF Data Services
  • First , How it was 2007 and whatwe have now in 2010 forAccessing Data in SharePoint
  • Accessing Data in 2007
  • Web Services Web services are available for use _vit_bin/Lists.asmx _vit_bin/Sites.asmx _vit_bin/Webs.asmx …. …..
  • Why Client OM Disadvantages of Web Services  Web Services can be complicated  Difficult to call from JavaScript  Often custom wrapper services are created  Customers solve the same problem over and over again
  • Accessing Data in 2010
  • Accessing data using REST
  • Integrating with SharePoint Web Services  More coverage Web Services Advanced Operations SharePoint Server Client Object Model Operations  Site, navigation  security services Client OM Advanced List  Very flexible and straight forward Operations Site Operations REST Security  Easiest to use REST  For fixed list schema Working with list data, fixed schema RPC http://msdn.microsoft.com/en-us/library/ms478653.aspx Server Side code , List View , Data View
  • How do I utilize client object model in my windows apps?.NET Client object model
  • Getting Started: 3 things to know1. ClientContext is the central object clientContext = new ClientContext(“http://mysite”);2. Before you read a property, you have toask for it clientContext.Load(list);3. All requests must be committed in a batch clientContext.ExecuteQuery();
  • Client Application Server Sequence of Client.svc commands: command 1; command 2; Execute commands command 3; in the batch:context.ExecuteQuery(); command 1; command 2; command 3; Process results Send results back
  • Equivalent ObjectsServer .NET Managed Silverlight JavaScript(Microsoft (Microsoft.SharePoint (Microsoft.SharePoint (SP.js).SharePoint) .Client) .Client.Silverlight)SPContext ClientContext ClientContext ClientContextSPSite Site Site SiteSPWeb Web Web WebSPList List List ListSPListItem ListItem ListItem ListItemSPField Field Field FieldMember names mostly the same from server to client(e. g., SPWeb.QuickLaunchEnabled = Web.QuickLaunchEnabled)
  • .Net CLR Client OM Provides easy access from remote .NET clients to manipulate SharePoint data Can be utilized from managed code – also from office clients etc. Assemblies  Microsoft.SharePoint.Client.dll (281kb)  Microsoft.SharePoint.Client.Runtime.dll (145kb)  To Compare: Microsoft.SharePoint.dll – 15.3MB
  • .NET Client OM Code Example 1ClientContext clictx = new ClientContext("http://intranet.contoso.com"); Site s1 = clictx.Site; Web w1 = clictx.Site.RootWeb; clictx.Load(s1); clictx.Load(w1); clictx.ExecuteQuery(); var lists1 = clictx.LoadQuery(w1.Lists); clictx.ExecuteQuery(); var lists2 = clictx.LoadQuery(w1.Lists.Include(l => l.Title)); clictx.ExecuteQuery(); var query1 = from l1 in w1.Lists where l1.Title != null select l1; clictx.ExecuteQuery();
  • Client Object ModelClientContext ctx = new ClientContext(“http://mysite”); Web web = ctx.Site.RootWeb; ctx.Load(web); ctx.Load(web, w => w.Title, w => w.Description); ctx.Load(web, w => w.Title, w => w.Lists .Include(l => l.Fields .Include(f => f.InternalName, f => f.Group)));
  • Uploading file example
  • Client Object ModelAuthentication Uses Windows Authentication by default Can be configured for Claims Based Authenticationctx.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication;ctx.FormsAuthenticationLoginInfo = new FormsAuthenticationLoginInfo("loginName", "password");
  • Client Object Model Limitations You still need to handle synch/update semantics (change log could help) No elevation of privilege capabilities Requests are throttled .net CLR has sync method; Silverlight CLR and Jscript are async
  • 21Demo
  • The JavaScript Client ObjectModel
  • Equivalent ObjectsServer .NET Managed Silverlight JavaScript(Microsoft (Microsoft.SharePoint (Microsoft.SharePoint (SP.js).SharePoint) .Client) .Client.Silverlight)SPContext ClientContext ClientContext ClientContextSPSite Site Site SiteSPWeb Web Web WebSPList List List ListSPListItem ListItem ListItem ListItemSPField Field Field FieldMember names mostly the same from server to client(e. g., SPWeb.QuickLaunchEnabled = Web.QuickLaunchEnabled)
  • JavaScript Client OM JavaScript Client OM is easily added to a SharePoint ASPX page - reference:  _layouts/sp.js  Add this using <SharePoint:ScriptLink> All libraries crunched for performance  Use un-crunched *.debug.js files with debug mode Method signatures can be different compared to .NET and Silverlight Different data value types
  • JavaScript Client OM C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions14TEMPLATELAYOUTS SP.js (SP.debug.js)  380KB (559KB) SP.Core.js (SP.Core.debug.js)  13KB (20KB) SP.Runtime.js (SP.Runtime.debug.js)  68KB (108KB)
  • JavaScript Client OM
  • 27Java Script Client OM Demo
  • REST access to SharePoint dataREST & WCF Data Services
  • Why a RESTful Interface for SP? Why REST  It is a natural fit for SharePoint data  Item == resource  Uniform interface and addressing scheme  Low barrier of entry, interoperability Why WCF Data Services  RESTful conventions & frameworks for data  Builds on top of standard AtomPub  Exactly the sort of convention we needed  Consistent tools and client libraries
  • A RESTful Interface for Data Just HTTP  Items as resources, HTTP methods (GET, PUT, …) to act  Leverage proxies, authentication, ETags, … Uniform URL convention  Every piece of information is addressable  Predictable and flexible URL syntax Multiple representations  Use regular HTTP content-type negotiation  JSON and Atom (full AtomPub support)
  • Accessing data using REST
  • Operations Operations map to HTTP verbs  Retrieve items/lists  GET  Create new item  POST  Update an item  PUT or MERGE  Delete an item  DELETE  These apply to links (lookups) as well SharePoint rules apply during updates  Validation, access control, etc.
  • URL ConventionsList of lists …/_vti_bin/listdata.svc/List listdata.svc/EmployeesItem listdata.svc/Employees(123)  Addressing lists and itemsSingle column listdata.svc/Employees(123)/FullnameLookup listdata.svc/Employees(123)/ProjecttraversalRaw value listdata.svc/Employees(123)/Project/Title/$valueaccessSorting listdata.svc/Employees?$orderby=FullnameFiltering listdata.svc/Employees?$filter=JobTitle eq SDEProjection listdata.svc/Employees?$select=Fullname,JobTitlePaging listdata.svc/Employees?$top=10&$skip=30Inline expansion listdata.svc/Employees?$expand=Project
  • 34REST Demo
  • Summary Overview of accessing Data in SharePoint Client Object Model  .NET Client Object Model  JavaScript and Client Object Model REST & WCF Data Services
  • Integrating with SharePoint Web Services  More coverage Web Services Advanced Operations SharePoint Server Client Object Model Operations  Site, navigation  security services Client OM Advanced List  Very flexible and straight forward Operations Site Operations Security REST  Easiest to use REST Working with list  For fixed list schema data, fixed schema Server Side OM
  • Accessing Data in 2010
  • Accessing data using REST