Presented by Pham Van Trung, this topic introduces the solutions to work with SharePoint 2010 from Client side, including:
- SP Client Object Model
- SP Silverlight Client Object Model
- SP ECMAScript Client Object Model
- SP WebServices ; WCF; REST; RPC
- Silverlight + JQuery + SP WebServices (http://spservices.codeplex.com/)
SharePoint Saturday Vietnam was sponsored by Officience. Visit http://www.officience.com/
2. Client side scenarios Story in SharePoint 2007 SharePoint 2010 Client Object Models Overview of the Client Object Models .NET Client Object Model Silverlight Client Object Model ECMAScript Client Object Model ADO.NET Data Services JQuery, SP WebServices and Silverlight Agenda
3. Scenarios Web Browsers Microsoft Office Applications Custom Applications Commonly interaction with SharePoint Display SharePoint data Manipulating with SharePoint data Client side scenarios
4. Story in SharePoint 2007 SharePoint Server Applications Web UIs Web Browsers SharePoint Object Model Web Services, RPC Applications Custom Services SharePoint Content DB
5. Client Object Model provides complete API instead of more services Provides an abstraction layer to return results as recognizable SharePoint objects Consistent developer experience across platforms (.NET, ECMAScript, Silverlight) Overview of the Client Object Models
6. SharePoint 2010 Client Object Models SharePoint Server Applications Client.svc Client Apps SharePoint Object Model Client OMs SharePoint Content DB
12. Site Collections and Sites Lists, List Items, Views, and List Schemas Files and Folders Web, List, and List Item Property Bags Web Parts Security Content Types Site Templates and Site Collection Operations Supported Areas
14. C:rogram Filesommon Filesicrosoft Sharedeb Server Extensions4SAPI Files Microsoft.SharePoint.Client.dll (282KB) Microsoft.SharePoint.Client.Runtime.dll (146 KB) Compare to SharePoint Server OM Microsoft.SharePoint.dll (16.2 MB) .NET Client Object Model
16. Think about efficiency All the properties are loaded in DEMO1 Specify the properties you need: ctx.Load(web, w=>w.Title); ctx.Load(list,l=>l.Title, l=>l.ItemCoun); ctx.ExecuteQuery(); .NET Client Object Model (cont)
17. DEMO 2 Specifying properties to load .NET Client Object Model (cont)
18. Loading List Items List Items are always loaded using a CAML Query [[Code]] - tbd .NET Client Object Model (cont)
19. DEMO 3 Loading List Items .NET Client Object Model (cont)
20. DEMO 4 Creating and Updating List Items .NET Client Object Model (cont)
21. C:rogram Filesommon Filesicrosoft Sharedeb Server Extensions4EMPLATEAYOUTSlientBin Files: Microsoft.SharePoint.Client.Silverlight.dll (266K) Microsoft.SharePoint.Client.Silverlight.Runtime.dll (142K) Silverlight Client Object Model
27. LINQ to SP not implemented in Silverlight ListData.svc provides RESTful access ADO.NET Data Services ListData.svc Loads ADO.NET Data Services handler assembly
SharePoint Object Model is the main component when working with SharePoint but it’s only available on the SharePoint ServerApplications using it must run on a SharePoint ServerThe Applications can connect directly to SharePoint Content DB, but this case should never happenedThe SharePoint Content DB is very complexThe DB is maintain by MS, and could be updated on the hotfixs…Clients working with SharePointVia Web Browsers with data rendered via Web ControlsVia Web Services (Standard SP Web Services and Custom Web Services)Not providing all the functions of SharePoint Object Model, need to add more functions on Web Services after an update or create custom Web ServicesWeb Services are not easy to useInput parameters and return result use XML documentsXML data needs to parsed manually – not serialize or deserializeNot very intuitiveRPC: Remote Procedure Call Protocol (owssvr.dll)Using by SharePoint DesignerNot provides all the functions on SharePoint Object ModelCustom Services: FTP, WCF…
Throughout each SharePoint release, Microsoft receives more and more requests for new Web ServicesInstead of continuously building new Web services (and replacing existing ASMX services with WCF services), they now provide a client object modelThe client object model provides an abstraction layer so process off the SharePoint server can interact with SharePoint using a consistent API that is very closely matched to the familiar server API
Design GoalsConsistencyEfficiency
The Client Object Model contains a lot of overlap coverage with the full SharePoint API
Similar to programming against server objects in the server context, the new client-side object models use a ClientContext object as the "center of gravity" for all operations. The process of obtaining and working with sites and data begins by retrieving a context object.Show the various resources and their locationsServer – Microsoft.SharePoint – [..]\\14\\ISAPI .NET – Microsoft.SharePoint.Client – [..]\\14\\ISAPISilverlight – Microsoft.SharePoint.Client.Silverlight – [..]\\14\\LAYOUTS\\ClientBinECMAScript– SP.js - [..]\\LAYOUTS
Keep efficiency in mindSpecifying the properties to loadQuickly generate CAML using the CreateAllItemsQuery() method
By default, the managed client object models authenticate users by using their Windows credentials (DefaultCredentials). Optionally, you can change the authentication mode on the ClientContext object and specify using Forms authentication instead. A user must then supply a user name and password through properties on ClientContext. Behind the scenes, Windows SharePoint Services “14” calls the Authentication Web service, obtains the correct cookie, and then makes the necessary object model calls. To run managed client code against a Forms authentication server, you must change to Forms authentication. This requirement does not apply to the JavaScript object model.The managed client object models provide a ClientAuthenticationMode enumeration whose values are Anonymous, Default, andFormsAuthentication. To specify Forms authentication, use code similar to the following:clientContext.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication;In addition to setting the authentication mode, you must specify the user name and password information, such as follows:FormsAuthenticationLoginInfoformsAuthInfo = new FormsAuthenticationLoginInfo("MyUser", "MyPassword");clientContext.FormsAuthenticationLoginInfo = formsAuthInfo; Note: Currently, the account name and password in formsAuthInfo are sent in clear text, so you must use HTTPS protocol instead of HTTP.
• Callback methods are executed on another thread than the UI thread• Use Invokes to alter the UI from the Use Invokes to alter the UI from the background thread!A Web Part can be a host for SilverlightSharePoint ships with Silverlight web partThe web part can contain custom properties that are sent to Silverlight via the InitParameters propertyThe XAP file can be deployed to LAYOUTS and loaded at run timeThe Silverlight application can then make use of the Client OM.For Silverlight client installations, Microsoft SharePoint Foundation deploys Microsoft.SharePoint.Client.Silverlight.dll and Microsoft.SharePoint.Client.Silverlight.Runtime.dll into a special "Scripts only" folder of the /_layouts virtual directory named clientbin. This folder is designed to be a standard place for hosting assemblies that are used in Silverlight.
Compressed and crunched .js files for the ECMAScriptobject model, named SP.js, SP.Core.js, and SP.Runtime.js, are installed in the /_layouts directory. Microsoft SharePoint Foundation also includes uncrunched, debug versions of the .js files named SP.debug.js, SP.Core.debug.js, and SP.Runtime.debug.js. You can toggle which .js file is used in Microsoft SharePoint Foundation by setting ScriptMode="Debug" in web.config. If you add <SharePoint:ScriptLinkrunat=”server” Name=”sp.js” Localizable=”false” LoadAfterUI=”true” /> to the page, the Microsoft.SharePoint.WebControls.ScriptLink server control registers all dependencies.You should be aware of the following important differences between the ECMAScriptand managed client object models.The method signature may be different, as with the ClientContext constructorThe two object models use different data value types. The ECMAScriptobject model does not have equivalents for all the data value types in the .NET Framework managed object model. ECMAScriptregards StringCollection as string[]. On the other hand, ECMAScripthas some values that the .NET Framework does not have, such as NaN, or negative and positive infinity.The ECMAScript object model requires that you include security validation on the page through a FormDigest control; for example, <SharePoint:FormDigest id="MyFormDigest" runat="server"/>.
Client side scenariosStory in SharePoint 2007 SharePoint 2010 Client Object ModelsOverview of the Client Object Models.NET Client Object ModelSilverlight Client Object ModelECMAScript Client Object ModelADO.NET Data ServicesJQuery, SP WebServices and Silverlight