41
©2010 Microsoft Corporation. All rights reserved. RTM Content - Published May 2010 Advanced Developer Training

What is all about and how does it work? Client Application

Embed Size (px)

Citation preview

Page 1: What is all about and how does it work? Client Application

©2010 Microsoft Corporation. All rights reserved. RTM Content - Published May 2010

Advanced Developer Training

Page 2: What is all about and how does it work? Client Application

©2010 Microsoft Corporation. All rights reserved. RTM Content - Published May 2010

Using the Client Object Model and REST to Access SharePoint 2010

NameTitleCompany

Page 3: What is all about and how does it work? Client Application

©2010 Microsoft Corporation. All rights reserved. RTM Content - Published May 2010

Agenda

Introduction to Client Object Model.NET Client Object ModelSilverlight and Client Object ModelJavaScript and Client Object ModelREST & WCF Data Services

Page 4: What is all about and how does it work? Client Application

©2010 Microsoft Corporation. All rights reserved. RTM Content - Published May 2010

INTRODUCTION TO CLIENT OBJECT MODEL

What is all about and how does it work?

Page 5: What is all about and how does it work? Client Application

©2010 Microsoft Corporation. All rights reserved. RTM Content - Published May 2010

Accessing Data in SharePoint 2007

SharePoint Data

SharePoint API

Web Service

Client Application

ServerApplication

Page 6: What is all about and how does it work? Client Application

©2010 Microsoft Corporation. All rights reserved. RTM Content - Published May 2010

How can this be improved

Web Services can be complicatedDifficult to call from JavaScriptOften custom wrapper services are createdCustomers solve the same problem over and over again

Page 7: What is all about and how does it work? Client Application

©2010 Microsoft Corporation. All rights reserved. RTM Content - Published May 2010

Client Object Model

Simple and easy to use API to Add, Retrieve, Update and Manage Data in SharePoint.

.Net CLR SilverlightJavaScri

pt

SharePoint Data

Client Application

Consistent Efficient

Page 8: What is all about and how does it work? Client Application

©2010 Microsoft Corporation. All rights reserved. RTM Content - Published May 2010

Content database

Accessing Data with Client OM

SharePoint Data

SharePoint API

Web Service

Client Application

ServerApplication

Client.svc

Client Application

Client OM

JSON XML

WPF/WinForm/OfficeSilverlightJavaScript

Page 9: What is all about and how does it work? Client Application

©2010 Microsoft Corporation. All rights reserved. RTM Content - Published May 2010

Equivalent Objects

Server (Microsoft.SharePoint)

.NET Managed(Microsoft.SharePoint.Client)

Silverlight(Microsoft.SharePoint.Client.Silverlight)

JavaScript(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

Member names mostly the same from server to client (e. g., SPWeb.QuickLaunchEnabled = Web.QuickLaunchEnabled)

Page 10: What is all about and how does it work? Client Application

©2010 Microsoft Corporation. All rights reserved. RTM Content - Published May 2010

Site

Web

ListItem

Field

View

Form

Folder

List

NavigationNode

Navigation

UserCustomAction

ContentType

RoleDefinition

WorkflowAssociation

WorkflowTemplate

RoleAssignment

Change

WebPart

File

User Interface

Data and Schema

Security

Logic

Major Objects in Client Object Model

Page 11: What is all about and how does it work? Client Application

©2010 Microsoft Corporation. All rights reserved. RTM Content - Published May 2010

1. ClientContext is the central object

2. Before you read a property, you have to ask for it

3. All requests must be committed in a batchclientContext.ExecuteQuery();

clientContext.Load(list);

clientContext = new ClientContext(“http://mysite”);

Getting Started: 3 things to know

Page 12: What is all about and how does it work? Client Application

©2010 Microsoft Corporation. All rights reserved. RTM Content - Published May 2010

High level handling of commands

XML

JSON

Execute commandsin the batch:

Client.svcSequence of commands:

context.ExecuteQuery();

command 1;command 2;command 3;

Send results back

command 1;command 2;command 3;

Process results

ServerClient Application

Page 13: What is all about and how does it work? Client Application

©2010 Microsoft Corporation. All rights reserved. RTM Content - Published May 2010

Client Object Model Limitations

You still need to handle synch/update semantics (change log could help)No elevation of privilege capabilitiesRequests are throttled.net CLR has sync method; Silverlight CLR and Jscript are async

Page 14: What is all about and how does it work? Client Application

©2010 Microsoft Corporation. All rights reserved. RTM Content - Published May 2010

.NET CLIENT OBJECT MODELHow do I utilize client object model in my windows apps?

Page 15: What is all about and how does it work? Client Application

©2010 Microsoft Corporation. All rights reserved. RTM Content - Published May 2010

.Net CLR Client OM

Provides easy access from remote .NET clients to manipulate SharePoint data

Can be utilized from managed code – also from office clients etc.

AssembliesMicrosoft.SharePoint.Client.dll (281kb)Microsoft.SharePoint.Client.Runtime.dll (145kb)

To Compare: Microsoft.SharePoint.dll – 15.3MB

Page 16: What is all about and how does it work? Client Application

©2010 Microsoft Corporation. All rights reserved. RTM Content - Published April 2010

.NET Client OM

Page 17: What is all about and how does it work? Client Application

©2010 Microsoft Corporation. All rights reserved. RTM Content - Published April 2010

Uploading file example

In 2007 version submitting files to SharePoint was suprisingly difficult – in 2010, using client object model, we can accomplish this extremely easily.

Page 18: What is all about and how does it work? Client Application

©2010 Microsoft Corporation. All rights reserved. RTM Content - Published May 2010

Hello, Client OM

demo

Page 19: What is all about and how does it work? Client Application

©2010 Microsoft Corporation. All rights reserved. RTM Content - Published May 2010

SILVERLIGHT AND CLIENT OBJECT MODEL

Page 20: What is all about and how does it work? Client Application

©2010 Microsoft Corporation. All rights reserved. RTM Content - Published May 2010

Silverlight in SharePoint 2010

Can use Silverlight in separate ASPX page or in Web PartThe web part can contain custom properties that are sent to Silverlight via the InitParams propertyThe XAP file can be deployed to LAYOUTS or content database and loaded at run timeThe Silverlight application can then make use of the Client OM

Page 21: What is all about and how does it work? Client Application

©2010 Microsoft Corporation. All rights reserved. RTM Content - Published May 2010

Web ServicesAdvanced OperationsSharePoint Server Operations

Client OMAdvanced List OperationsSite OperationsSecurity

RESTWorking with list data,fixed schema

Integrating with SharePoint

Web ServicesMore coverage

Client Object ModelSite, navigationsecurity servicesVery flexible and straight forward

RESTEasiest to useFor fixed list schema

Page 22: What is all about and how does it work? Client Application

©2010 Microsoft Corporation. All rights reserved. RTM Content - Published May 2010

Silverlight CLR Client OM

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions \14\TEMPLATE\LAYOUTS\ClientBin

Microsoft.SharePoint.Client.Silverlight262KB

Microsoft.SharePoint.Client.Silverlight.Runtime

138KB

Redistributable planned for the assemblies

Also XAP file that can be dynamically included to Silverlight application

Page 23: What is all about and how does it work? Client Application

©2010 Microsoft Corporation. All rights reserved. RTM Content - Published April 2010

Silverlight Client OM

Page 24: What is all about and how does it work? Client Application

©2010 Microsoft Corporation. All rights reserved. RTM Content - Published May 2010

Building and Deploying Silverlight

Built in support in Visual Studio 2010Sandboxed and Farm Solutions supportF5 deploy and debug experience

SharePoint WSP

Silverlight XAP Deploy as SharePoint

Farm or Sandboxed Solution

Visual Studio builds WSP package on F5

Page 25: What is all about and how does it work? Client Application

©2010 Microsoft Corporation. All rights reserved. RTM Content - Published May 2010

Custom Silverlight Web Part with client OM

demo

Page 26: What is all about and how does it work? Client Application

©2010 Microsoft Corporation. All rights reserved. RTM Content - Published May 2010

THE JAVASCRIPT CLIENT OBJECT MODEL

Page 27: What is all about and how does it work? Client Application

©2010 Microsoft Corporation. All rights reserved. RTM Content - Published May 2010

JavaScript Client OM

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

_layouts/sp.jsAdd this using <SharePoint:ScriptLink>

All libraries crunched for performanceUse un-crunched *.debug.js files with debug mode

Method signatures can be different compared to .NET and SilverlightDifferent data value types

Page 28: What is all about and how does it work? Client Application

©2010 Microsoft Corporation. All rights reserved. RTM Content - Published May 2010

JavaScript Client OM

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS SP.js (SP.debug.js)

380KB (559KB)

SP.Core.js (SP.Core.debug.js)13KB (20KB)

SP.Runtime.js (SP.Runtime.debug.js)68KB (108KB)

Page 29: What is all about and how does it work? Client Application

©2010 Microsoft Corporation. All rights reserved. RTM Content - Published April 2010

JavaScript Client OM

Page 30: What is all about and how does it work? Client Application

©2010 Microsoft Corporation. All rights reserved. RTM Content - Published May 2010

JavaScript Client OM

demo

Page 31: What is all about and how does it work? Client Application

©2010 Microsoft Corporation. All rights reserved. RTM Content - Published May 2010

REST & WCF DATA SERVICESREST access to SharePoint data

Page 32: What is all about and how does it work? Client Application

©2010 Microsoft Corporation. All rights reserved. RTM Content - Published May 2010

Why a RESTful Interface for SP?

Why RESTIt is a natural fit for SharePoint dataItem == resourceUniform interface and addressing schemeLow barrier of entry, interoperability

Why WCF Data ServicesRESTful conventions & frameworks for dataBuilds on top of standard AtomPubExactly the sort of convention we neededConsistent tools and client libraries

Page 33: What is all about and how does it work? Client Application

©2010 Microsoft Corporation. All rights reserved. RTM Content - Published May 2010

A RESTful Interface for Data

Just HTTPItems as resources, HTTP methods (GET, PUT, …) to actLeverage proxies, authentication, ETags, …

Uniform URL conventionEvery piece of information is addressablePredictable and flexible URL syntax

Multiple representationsUse regular HTTP content-type negotiationJSON and Atom (full AtomPub support)

Page 34: What is all about and how does it work? Client Application

©2010 Microsoft Corporation. All rights reserved. RTM Content - Published May 2010

Client Application

Content database

Accessing data using REST

SharePoint Data

SharePoint API

ListData.svc

AtomJSON Post, Put, Get

Any application or platform - .NET, Java,Flash, Silverlight

Page 35: What is all about and how does it work? Client Application

©2010 Microsoft Corporation. All rights reserved. RTM Content - Published May 2010

Operations

Operations map to HTTP verbsRetrieve items/lists GETCreate new item POSTUpdate an item PUT or MERGEDelete an item DELETEThese apply to links (lookups) as well

SharePoint rules apply during updatesValidation, access control, etc.

Page 36: What is all about and how does it work? Client Application

©2010 Microsoft Corporation. All rights reserved. RTM Content - Published May 2010

URL Conventions

Addressing lists and itemsList of lists …/_vti_bin/listdata.svc/

List listdata.svc/Employees

Item listdata.svc/Employees(123)

Single column listdata.svc/Employees(123)/Fullname

Lookup traversal

listdata.svc/Employees(123)/Project

Raw value access

listdata.svc/Employees(123)/Project/Title/$value

Sorting listdata.svc/Employees?$orderby=Fullname

Filtering listdata.svc/Employees?$filter=JobTitle eq 'SDE'

Projection listdata.svc/Employees?$select=Fullname,JobTitle

Paging listdata.svc/Employees?$top=10&$skip=30

Inline expansion

listdata.svc/Employees?$expand=Project

Presentation options

Page 37: What is all about and how does it work? Client Application

©2010 Microsoft Corporation. All rights reserved. RTM Content - Published May 2010

Visual Studio 2010 support

Integrated support for Data ServicesClient library for .NET and SilverlightIDE integration, “Add Service Reference”Data service visualizer to explore site structure

Feature rich client library for .NETTyped experience through code-genLINQ supportChange tracking, batching, blobs, all supported

Requires installation of WCF data services 1.5 to server side

Page 38: What is all about and how does it work? Client Application

©2010 Microsoft Corporation. All rights reserved. RTM Content - Published May 2010

REST & WCF Data Services

demo

Page 39: What is all about and how does it work? Client Application

©2010 Microsoft Corporation. All rights reserved. RTM Content - Published May 2010

Summary

Introduction to Client Object Model.NET Client Object ModelSilverlight and Client Object ModelJavaScript and Client Object ModelREST & WCF Data Services

Page 40: What is all about and how does it work? Client Application

©2010 Microsoft Corporation. All rights reserved. RTM Content - Published May 2010

Page 41: What is all about and how does it work? Client Application

©2010 Microsoft Corporation. All rights reserved. RTM Content - Published May 2010

© 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.

The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after

the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.