Sunday, July 15, 2012

ClientObjectModel SharePoint 2010


Client Object model is introduced in SharePoint 2010 because of customer's constant request for web services to pull SharePoint data outside of SharePoint. The web services that SharePoint provided did limited things. So customers had to write there own web services to pull SharePoint data.
Client object model has 3 flavors: .Net, ECMAScript, Silverlight
DLLs used for Client Object model: Microft.SharePoint.Client.dll, Microft.SharePoint.Client.Runtime.dll
Code generator automatically converts Server OM into Client OM.
 Client communicate to the server thorough Client OM which under the hood uses Client.svc WCF service to communicate with SharePoint Server. Client.svc service uses Server OM as per client request and return result to the client in JSON format.
 Create ClientContext object by passing url of SharePoint. Use clientContext.Load(); where you can use lamda expression to retrieve light weight objects and clientContext.ExecuteQuery();
 Silverlight client OM is similar to Client OM. Microft.SharePoint.Client.Silverlight.dll. The difference is ExecuteQueryAsync(getlistdata,null); is used. So the control goes to background. To bring back the control to UI in getlistdata() call dispather.beginInvoke(loadfile); Then control comes to UI level and write Client OM in loadfile();
 ECMAScript. <SharePoint:Scriptlink Name=SP.js> use sp.clientcontext.get_current(); You cannot go to other site to fatch data. we have to use executequeryAsync(delegate pass(),delegate fail()); you can use this in aspx page where you can fatch site object and work with it aslo using jquery.
 if you do not want to use client object model we can use ADO.NET Data Services where we can use REST to access web service List.svc to access SharePoint list.

No comments:

Post a Comment