Client Object Model and its Equivalent Objects in SharePoint 2010


This article explains the need for a Client Object model;  supported areas and the equivalent objects.

Instead of continuously building new Web services (and replacing existing ASMX services with WCF services), they now provide a client object model.

Why Client Object Model?
  1. More SharePoint Web services is a major request.
  2. Client Object Model Provides Complete API Instead of more services.
  3. The client object model provides an abstraction layer so process off the SharePoint server can interact with SharePoint using a consistent API that is very closely matched to the familiar server API
  4. Consistent developer experience across platforms (.NET, ECMAScript, Silverlight)
The Client Object Model contains a lot of overlap coverage with the full SharePoint API

List of Supported Areas by using Client Object Model: 
  • Site Collections and Sites 
  • Lists, List  Items, Views , and List  Schemas 
  • Files and Folders
  • Web, List, and List Item Property Bags
  • Web Parts
  • Security
  • Content Types
  • Site Templates and Site Collection Operations
Now will see the list of Equivalent objects in SharePoint 2010.

The new client-side object models use a Client Context object as the "center of gravity" for all operations. The process of obtaining and working with sites and data begins by retrieving a context object.

Using  Server, .net Managed , Silverlight  and ECMA Script

Server 
(Microsoft
.SharePoint)
.NET Managed
(Microsoft.SharePoint
.Client)
Silverlight
(Microsoft.SharePoint
.Client.Silverlight)
ECMAScript
(SP.js)
SPContext ClientContext ClientContext ClientContext 
SPSite Site Site Site
SPWeb Web Web Web
SPList List List List
SPListItem ListItem ListItem ListItem
SPField Field Field Field

Now will see the various resources and their locations
  • Server - Microsoft.SharePoint - [..]\14\ISAPI 
  • .NET - Microsoft.SharePoint.Client - [..]\14\ISAPI
  • Silverlight - Microsoft.SharePoint.Client.Silverlight - [..]\14\LAYOUTS\ClientBin 
  • ECMAScript - SP.js - [..]\LAYOUTS 
Compressed and crunched .js files for the ECMAScript object model, named SP.js,  SP.Core.js,  and SP.Runtime.js, are installed in the  /_layouts directory.

ECMAScript Client OM is easily added to a SharePoint ASPX page - reference:

To use the "_layouts/sp.js"   Add this using <SharePoint:ScriptLink>

Example:-

<SharePoint:ScriptLink  runat="server" Name="sp.js" Localizable="false" LoadAfterUI="true" />

Note:- Microsoft.SharePoint.WebControls.ScriptLink server control registers all dependencies

Things to be aware of the following important differences between the ECMA script and Managed client object models
  • ECMAScript and managed client object models.
  • The method signature may be different, as with the ClientContext constructor
  • The two object models use different data value types. The ECMAScript object model does not have equivalents for all the data value types in the .NET Framework managed object model. 
  • ECMAScript regards StringCollection as string[]. On the other hand, ECMAScript has some values that the .NET Framework does not have, such as NaN, or negative and positive infinity.
The ECMAScript object model requires that you include security validation on the page through a FormDigest control; 

Example:-

 <SharePoint:FormDigest id="MyFormDigest" runat="server"/>.