by Deepak

2014-07-15

1. Introduction to Client Object Model.

Client Object Model is nugget feature of SharePoint 2010. It is the subset of server object model which defined in Microsoft.sharepoint.dll it is used to manipulate and consume share point data. Client object Model Implement on Window communication Foundation (WCF) service (…/_vti_bin/client.svc)

Note:

  1. You Need Microsoft.sharepoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dll For working with client object Model
  2. Location of dll  C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI
  3. You Need Microsoft.SharePoint.Client. Namespace on working with client object Model
  4. Client Object Model Classes are as follows

ClientContext : ClientContext class is used to context information about such objects as the current web application, site, site collection, or server version.

Site : site class is used to get the site collection.

Web :web class is used to get the web on current site collection.

List :List is used to get the list.

ListItem :ListItem class is used to get the ListItem.

 2. How Client Object Model Work?

The Client OM send request as an XML format and server will return a JSON (java script Object Notation) which is converted to the appropriate Object Model.

Following diagram is the easier way to access SharePoint 2010 data using Client Object Model

Client.svc:

Client object model is WCF Web Service which is responsible for Communicating between client object model and share Point Data. Client.svc is located along with all other SharePoint Web Services. The response from Client.svc Web Service is sent as JSON format.

Client.SVC service has one method (ProcessQuery ) which takes SteramObject

ProcessQuery method found in Microsoft.SharePoint.Client.ServerRuntime.dll and private class ClientRequestServiceImpl

Location of client.svc service: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI\Client.SVC

 3. Why We Use Client Object Model?

Share point installation is not required on development machine only you need to required dll’s if you are develop window application or any other application

Less deployment problems and client object model is very easy for end user

Flexibility in language: you can use three different Language for Client object model

Microsoft .NET

Silverlight

ECMA Script (JavaScript /JScript)

Optimization in query speed: In Client OM, you do not need to install the SharePoint Server required by the Server Object Model. Thus Client OM provides much ease to the end user.

Example of Client Object Model (.Net Managed)

//Method Add items into list

private void AddNewListItem()

{
    var clientContext = new ClientContext(“your site URL/”);
    var list = clientContext.Web.Lists.GetByTitle(“ListName”);
    var param = new ListItemCreationInformation();
    var newItem = list.AddItem(param);
    newItem["Name"] = “Deepak Chauhan”;
    newItem["Address"] = "India”;
    newItem.Update();
    clientContext.ExecuteQuery();
}

 

About the author 

Deepak