Click here to Skip to main content
15,885,182 members
Articles / Desktop Programming / WPF

SharePoint 2010: Client Object Model – An Introduction

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
9 Feb 2010CPOL4 min read 33.5K   10   3
Introduction to SharePoint 2010 Client Object Model

Introduction

SharePoint 2007 allows using its Object model to run against a server running SharePoint. For clients (not running SharePoint in the box), the simplest way to communicate with SharePoint server is web services. SharePoint Client Object Model (OM) can be run on client PC (where SharePoint is not installed) to communicate with SharePoint server. So whereas SharePoint (Server) Object Model runs in a SharePoint server and can manipulate SharePoint objects, client OM can run in client PC and communicate with SharePoint server remotely.

SharePoint 2010 introduces three new client APIs which can be used to interact with SharePoint sites. The three APIs are targeted for three different types of clients:

  1. For .NET managed applications (for example, console applications, window applications, web applications, etc. which are not running inside SharePoint Context).
  2. For Silverlight applications.
  3. For using with JavaScript (called ECMAScript). This API is only available for applications hosted inside SharePoint (for example, web part deployed in SharePoint site can use this JavaScript API for accessing SharePoint from browser using JavaScript).

I'll explain all of these API sets gradually. In this post, I'll explain some basic problems SharePoint developers faced during development with SharePoint 2007 in the absence of Client Object Model.

Why Client Object Model (OM)? 

SharePoint 2007 had no Client Object model available. So you may ask why this is introduced in SharePoint 2010? We had no problem without Client OM and millions of sites are running smoothly without having Client OM. The main reason is that Microsoft has found lot of requests from SharePoint users to introduce more and more web services to get data out of SharePoint in the last couple of years. But introducing web services will not fix the issues, as Microsoft found, because then the request for more functionality in the web services will continue. Even if Microsoft provides a good numbers of web services with SharePoint, customization in web services will be required for different clients and this will make the out of the box web services unusable. Also introducing a large number of web services will be a waste as not all companies will use all the web services functionalities.

In response to add more web services from users, Microsoft has taken a different approach called Client Object Model (OM). This SharePoint Client OM will allow getting data out of SharePoint from PCs that are not hosting SharePoint. Also Client OM provides complete API to interact with SharePoint Server which is more intuitive and useful and very much similar to the SharePoint Object Model.

Similarity with SharePoint Object Model 

Now SharePoint developers will fear that the Client Object Model will introduce a new burden for them to get used to it. But thSharePoint team provided great efforts to keep the Client OM familiar with SharePoint Object Model. The following table shows the equivalent objects in Client and SharePoint Object Model.

Server (Microsoft.SharePoint) Client Object Model
SPContext ClientContext
SPSite Site
SPWeb Web
SPList List
SPListItem ListItem
SPField Field

So the class names in Client OM are similar as in the SharePoint Object Model. However the way client OM will be used is a bit different than the usual SharePoint Object Model that we will explore in the upcoming posts.

How Client OM is Developed and Work under the Hood? 

It’s interesting how SharePoint team has developed the same set of classes for three different sets of applications (Managed, Silverlight and ECMAScript). There is the same class ListItem for three different sets of applications. As shown in the following table, three different assemblies/files are used for three different types of applications.

Client Type Assembly/File
Managed Client Microsoft.SharePoint.Client
Silverlight Microsoft.SharePoint.Client.Silverlight
ECMAScript SP.js

To ensure the same class object (say ListItem) behaves similarly in three different types of applications, the SharePoint team followed the steps described below:

  1. SharePoint team first set attributes to the SharePoint classes and methods and properties that need to be exposed in Client OM.
  2. Then a code generator is run against the SharePoint object model to generate client OM automatically.

This automated code generation has ensured maximum compatibility between these three sets of APIs. As the following figure shows, client communicates 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 returns the result to the client in JSON format.

image
Figure: How Client Object model works with Server

With this new Client OM, we almost don't need to use web service to communicate with SharePoint server. However, the client OM has just been released and we will find its shortcomings as well as use it more and more in live projects. In my next posts, I'll go through three different kinds of Client OM (Managed .NET, Silverlight and ECMAScript).

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect ImpleVista Aps
Denmark Denmark
Sohel has more than six years of experience in professional software development with extensive involvement in Web based Object-Oriented, Multi-Tiered application design and development. He's Familiar with Test Driven Development (TDD) and refactoring techniques as well as having expertise in architecturing large enterprise applications. He has Experience in working with Content Management System and Portal Management System tools like SharePoint, DotNetNuke, Ektron.

Over last few years, he’s involved in development with projects on Microsoft SharePoint and received Microsoft MVP for SharePoint Server Development in the year 2011 and 2012. Currently he's working in a software company located Copenhagen,Denmark on a project integrating SharePoint and SAP. You can read his popular blog at: http://ranaictiu-technicalblog.blogspot.com

Comments and Discussions

 
GeneralSharePoint 2010, Client Object Model Pin
praveen.batula15-Apr-10 15:57
praveen.batula15-Apr-10 15:57 
GeneralRe: SharePoint 2010, Client Object Model Pin
Not Active22-Aug-11 10:50
mentorNot Active22-Aug-11 10:50 
GeneralGoo start Pin
praveen.batula9-Apr-10 9:05
praveen.batula9-Apr-10 9:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.