Managed Client Object Model on the desktop

SharePoint 2010 introduces the managed client object model which allows us to create applications using ECMAScript, .NET managed code, and Silverlight. This new object model is designed around the highly successful server object model and takes a lot of the interfaces directly from the server's API. That means knowing the server object model will provide for an easy transition to the client object model, and vice versa.

Note

ECMAScript is the scripting language standardized by Ecma International in the ECMA-262 specification and ISO/IEC 16262. For more information, please visit the Wikipedia description at the following URL:

http://en.wikipedia.org/wiki/ECMAScript

The client object model is not a perfect replication of the server object model. The reason for this design was to build an object model that provides for client level development needs. The result of not providing everything in the client object model that exists in the server object model is a smaller footprint on the libraries, and thus a shorter download time.

Because everything in the client object model exists in the server object model, making a call on these interfaces is a simple WCF service call that relays the information to the server in XML. The request is then performed using the server object model and the response is returned using JavaScript Object Notation (JSON) or OData. As we'll learn, this is important for writing Windows Phone 7 Applications.

ECMAScript interface

The .js files needed for the ECMAScript interface are automatically included in the standard SharePoint master page. There is nothing that needs to be added to the web pages to get this interface on the client. We just need to start using it.

Using the ECMAScript interface is relatively easy. We simply need to add a SharePoint Form Digest within the form for the page. These types of pages must run within the context of SharePoint and be deployed to the layouts folder, as described in previous chapters.

The form digest class inserts a security validation into the page. It creates a message digest that helps prevent a specific type of attack where a user is tricked into posting information to the server. Basically, this is analogous to the cookie jar that we created earlier. This security validation has a lifetime and cannot be copied and used on another computer.

The ECMAScript interface into SharePoint demonstrates how SharePoint sites were developed for SharePoint. This type of programming works great when we are concerned with websites, as we have been in previous chapters of this book. In Chapter 4 when we created our custom mobile home page, the next step was to create a custom master page that contained all of the required JavaScript files and go to town implementing the various lists and libraries contained within our SharePoint site.

For Windows Phone 7 application programming, building web pages isn't as exciting as building out full featured Silverlight applications.

Silverlight interface

In Silverlight, on the desktop we can reference the Client Object Model's DLL from the SharePoint SDK and build our applications against them. This makes for a very satisfying development environment.

The DLL's are registered into the Global Assembly Cache (GAC) on the developer's machine. To reference them in a project, carry out the following steps:

  1. Right click on References in Solution Explorer.
  2. Click on Add Reference.
  3. On the .NET tab of the Add References dialog box, select the following two DLL's
    • Microsoft.SharePoint.Client
    • Microsoft.SharePoint.Client.Runtime
  4. Finally, click on OK.

When the Silverlight application is deployed, the required DLL's are bundled inside the XAP. No additional download or installation is required on the client machine.

Windows Phone 7 applications, although written in Silverlight, only support a subset of Silverlight features. What this means for a developer trying to write Windows Phone 7 applications that take advantage of SharePoint features is that DLL's like those found in the client object model from the SharePoint SDK depend on DLL's that aren't available on Windows Phone 7. Specifically, System.Windows.Browser is missing from the phone. What are we to do in this situation? Enter WCF Data Services.

Note

In addition to ECMAScript and Silverlight, there are .NET managed code libraries that can be used to create WinForms or WPF applications that run on Windows. This is beyond the scope of this book, but for the most part the interfaces are the same as the Silverlight API. Their distribution model is slightly different though. One must use the SharePoint Foundation 2010 Client Object Model Redistributable package. Visit the following URL for more information:

http://msdn.microsoft.com/en-us/library/ee537247.aspx

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.27.171