Blog

SharePoint Client Object Model - Microsoft SharePoint

Excerpt by Doug Ware | January 06, 2014

A typical SharePoint site contains much information that is potentially useful to other systems. SharePoint provides a number of APIs that other systems can use to access and manipulate that information. SharePoint Foundation 2010 includes a new set of libraries, the SharePoint client object model, which client applications can use to access SharePoint's core services.

The SharePoint client object model is a set of managed code and JavaScript libraries that support traditional .NET assemblies and executables, Silverlight, and browser-based JavaScript. In the past, you had to work with SharePoint via SOAP-based Web services. These services consume and emit XML that the client must build and parse. The client object model does not require you to build and parse XML nor is it based on SOAP. Instead you use classes that are very similar to the ones you use when writing SharePoint code on the server. These classes act as proxies to a WCF service.

Problems Addressed

The client object model is actually a set of client and server proxies to a WCF service. However, you do not have to understand the WCF service because the client object model takes care of all of the tedious details of connecting to and communicating with the WCF service. This is a major improvement over the *.asmx (SOAP) services found in WSS 2.0 and WSS 3.0. To use the SOAP services you must understand SOAP, build and parse XML, and most importantly, understand the specific service. Since these services consume XML, knowledge of the SharePoint object model is only slightly helpful to understanding a given service.

Each of the services is a program with its own rules. Understanding how to write code to add an item to a list doesn't mean you know the specific SOAP service endpoint or how to format XML that the service understands. Apart from being complex, the SOAP services are inefficient. Accomplishing most tasks requires multiple round-trips to the server and multiple service endpoints. Those who use hosted SharePoint and can't deploy code to the farm have no choice and must use the services if they need integration.

However, due to the complexity and learning curve of the traditional services, most people build and deploy custom services that support specific use cases to integrate earlier versions of SharePoint with other applications. The traditional SOAP based services are still supported, but unless you are writing code to target both WSS 3.0 and SharePoint Foundation you should use the client object model.

Client Object Model Overview

When you use the client object model you work with classes and methods. There is still XML, but you don't see it or work with it. The client object model builds the XML based on your work. When it is time to do work on the server, the client object model passes the XML to the client.svc WCF service endpoint. SharePoint does whatever work is indicated by the XML and returns a JSON (JavaScript Object Notation) encoded response to the client object model which updates the state of any object instances as necessary. Figure 1 shows a conceptual view of the communication between the client and the server. Sharepoint_Client_object

Figure 1.The client object model and client service handle all communication and message formatting for you.

 

doug (frame 367 of smile clip)This post is an excerpt from the online courseware for our Microsoft SharePoint 2010 for Developers course written by expert Doug Ware.



Doug Ware

Doug Ware is a SharePoint expert and an instructor for many of our SharePoint 2007 and SharePoint 2010 courses. A Microsoft MVP several times over, Doug is the leader of the Atlanta .NET User Group, one of the largest user groups in the Southeast U.S., and is a frequent speaker at code camps and other events. In addition to teaching and writing about SharePoint, Doug stays active as a consultant and has helped numerous organizations implement and customize SharePoint.


This course excerpt was originally posted January 06, 2014 from the online courseware SharePoint 2010: Developer by Doug Ware