SharePoint Study Notes-architecture series-client Object Model of SharePoint)

Source: Internet
Author: User

After a look at the server-side object model of SharePoint, let's take a general look at the client Object Model (client object model: client om) of SharePoint ).

The first thing to understand is that the client model of SharePoint was introduced in sharepoint2010.

1. Why should we introduce the client object model?

This is because with the promotion of SharePoint, people find that sometimes they need to remotely access the SharePoint website and its List data from the client computer or server. SharePoint fundation is not installed on these client computers or servers, that is, a very common environment. It is almost impossible to access resources on a special platform such as SharePoint without any middle layer for support (of course, you can use web services to interact with SharePoint lists and other functions, but this is not easy. If the Web service does not provide the required functions, you can writeCodeIt is a more difficult task to provide new Web Services. Some IT departments are not allowed to use server-side code, or only code written by IT departments, so sometimes this is not feasible ). Therefore, Sharepoint introduces the client object model. Based on this client object model, it provides developers with corresponding APIs to support their access to remote SharePoint resources. The access method can be Windows applications on the client computer.Program, A Silverlight application or a Sharepoint M Web parts page of SharePoint, as shown in:

 

The introduction of the client object model solves the problem of how the Client Program understands the SharePoint object model. Only by understanding the SharePoint object model can the client perform operations on these SharePoint objects, namely: you can add and delete lists, add, update, and delete list items, modify documents in the document library, create websites, manage project permissions, and add and delete Web parts on the page.

2. What are the object models of the Sharepoint client and what APIs are provided?

Microsoft SharePoint 2010 software development kit (SDK) introduces three client APIs that allow you

1. scripts executed in the browser (ecmscript: JavaScript, JScript)

2. Code executed in. Net-managed applications (Microsoft. NET Framework 3.5 or later)

3. Microsoft Silverlight 2.0 APPLICATION

The executed code interacts with the SharePoint website.

Three client object models correspond to the above three APIs:

1. ecmascript (JavaScript, JScript) Client Object Model

2... Net Managed Client Object Model

3. Silverlight client Object Model

The above three client object models are available in Microsoft. sharepoint. A subset of the server object model defined in DLL, including the objects corresponding to the site collection level or lower-level main objects in the SharePoint Foundation hierarchy. To improve security and performance, the client object model focuses on APIs most relevant to client development and does not include all types and members represented in the server object model.

These three types of client object models of mongopoin share structural design features, such as the object model hierarchy, object identification, data retrieval semantics, client context, basic structure client object, set and exception handling. These object models are consistent with the SharePoint Foundation Server Object Model. Therefore, if you are familiar with server-side APIs, you can quickly learn to use client. Net hosted APIs, Silverlight APIs, or Javascript APIs. Although the client object model is not similar to the server object model, they are generally similar to each other. Therefore, after you have mastered a subset of the server object model, in this way, most of the content of other subsets is mastered. As long as possible, the new object model will borrow the asynchronous example in. NET Framework (especially ADO. net.

Note: Windows Phone 7 does not support Silverlight client object models in SharePoint

3. How does the Sharepoint client object model work?

The client environment is on the left and the Sharepoint Server Environment on the right.

Applications running in the client environment deal with SharePoint resources through APIS provided by the client object model. They interact with APIs in multiple ways, this interaction involves many aspects, such:

. Call the methods provided by the API and obtain the return value

. Pass the tag language (caml) of the Collaboration application to query and obtain results

. Set or get attributes

After you use APIs to execute specific tasks, the client object model binds these APIs to XML and sends them to the server running SharePoint Foundation. That is to say, the access request sent to the Sharepoint Server is transmitted in XML format, so it is represented as XML request.

After receiving the XML request, the server calls the appropriate Object Model (server om) on the server to collect the response and mark the response as a JavaScript Object (JSON ), then, the JSON file is sent back to the SharePoint Foundation 2010 Managed Client object model. The client object model then analyzes JSON and provides the result as a. NET Framework object (or JavaScript Object in Javascript) to the application.

Therefore, the client submits the request in XML format, and the server returns the request result in JSON format. Client applications directly deal with the client object model, while servers directly deal with the server object model.

Note that you need to control when the client object model starts to send XML to the server and when JSON is received from the server.

Whether to bind multiple method calls to the server to a single call is determined by the network speed, network latency, and required performance characteristics. If the client object model interacts with the server every time a method is called, the system performance will decrease and the network traffic will increase, resulting in system instability.

You can explicitly control when the client object model binds method calls and sends requests to the server. In this process, before starting interaction with the server, you must specify what content you want to retrieve from the server. This is the biggest difference between the client object model and the server object model.

 

4. How does a client application obtain the client object model?

When talking about how client applications interact with SharePoint servers through the client object model, how can client applications have the Sharepoint client object model?

In fact, if your client application wants to use the client object model, you can obtain the appropriate. DLL or. local copy of The JS file, because the client Object Model of Sharepoint is through these "proxies. JS and managed. DLL files are provided to client applications.

Therefore, the client Object Model of mongopoin is represented by a proxy. JS and hosting. provided by the DLL file, you can reference these object models in custom applications (such as other object models. These object models are implemented as windows Communication Foundation (WCF) services (.../_ vti_bin/client. SVC), but Web binding is used for effective request batch processing. All operations are actually asynchronous operations. commands are serialized into XML and sent to the server through an HTTP request. For each command, the corresponding server object model is called, and the server returns a response in the JavaScript Object Notation (or JSON) compression format to the client, the proxy will analyze the response and associate it with the appropriate object. This is what we described above.

The following describes how to obtain local copies of these. dll or. js files:

1. If you are developing a. Net-based application

Microsoft SharePoint Foundation 2010 installed Microsoft in % ProgramFiles % \ common files \ microsoft shared \ Web Server Extensions \ 14 \ ISAPI. sharepoint. client. DLL and Microsoft. sharepoint. client. runtime. DLL.

To make the Windows Forms, Windows Presentation Foundation (WPF), or other calls you develop. if the application hosting the SharePoint Foundation client API in. net works properly, the client computer must have the SharePoint Foundation client DLL installed (referenced) in the preceding location. You must have Microsoft. sharepoint. client. DLL and Microsoft. sharepoint. client. runtime. dll can be used. net managed object model remote development solution. That is to say, to use a DLL containing. Net-Managed Client APIs on a client computer, you must use Microsoft to distribute them along with the application.

2. If you are developing a Silverlight Application

For the Silverlight client, Microsoft SharePoint Foundation 2010 sets Microsoft. sharepoint. client. silverlight. DLL and Microsoft. sharepoint. client. silverlight. runtime. DLL is deployed in a special script-only folder % ProgramFiles % \ common files \ microsoft shared \ Web Server Extensions \ 14 \ template \ layouts \ clientbin. This folder is a standard location used to hold the Assembly used in Silverlight (this assembly is contained in the file Microsoft. Sharepoint. Client. xap. You must have both Microsoft. Sharepoint. Client. Silverlight. dll and Microsoft. Sharepoint. Client. Silverlight. runtime. DLL to use the Silverlight Object Model for remote development solutions.

Silverlight developers can have two options:

First, the client DLL (Microsoft. sharepoint. client. silverlight. DLL and Microsoft. sharepoint. client. silverlight. runtime. DLL) and your Silverlight. xap files are packaged together for download.

The other is to load the Microsoft. sharepoint. client. xap file, because this file contains the client DLL (Microsoft. sharepoint. client. silverlight. DLL and Microsoft. sharepoint. client. silverlight. runtime. DLL ).

Microsoft SharePoint Foundation 2010 supports implementing the Silverlight client Object Model in two types of contexts: silverlight Web Components and Silverlight cross-origin Data Access System (where Silverlight applications can interact with Microsoft SharePoint Foundation 2010 data ). The third possible approach is to modify the Client Access Cross-Domain Policy on the server, which causes security risks. Therefore, this approach is not supported in SharePoint Foundation 2010.

3. If you are developing an ecmascript-based page application

Reduced ecmascript (JavaScript, JScript) Client object model. JS files (such as sp. JS, SP. core. JS, SP. ribbon. JS and sp. runtime. JS) installed in the % ProgramFiles % \ common files \ microsoft shared \ Web Server Extensions \ 14 \ template \ layouts directory. When the client computer browses any SharePoint Foundation page that uses the standard SharePoint Foundation master page, these. js files are downloaded to the client. That is to say, the. js files that contain the Javascript client API are referenced on the standard SharePoint Foundation master page, so they are automatically downloaded to the client and support the client to use its client object model.

To use a custom parent page, you must reference these. js files when using the client object model.

SharePoint Foundation will also install unzipped and debugged versions in the same directory. JS files, such as sp. debug. JS, SP. core. debug. JS, SP. ribbon. debug. JS and sp. runtime. debug. and you can specify whether to use the debug version.

The default master page in SharePoint Foundation inserts a scriptmanager control in the webpage and sets the scriptmode attribute of the control to auto by default. Add <deployment retail = "false"/> to the Web. the system in the config file (in the % inetpub % \ wwwroot \ WSS \ virtualdirectories \ 80 directory. in the web section, you can replace this default setting and use debugging. JS file.

Ecmascript (JavaScript, JScript) object model is introduced to Microsoft SharePoint Foundation 2010 together with the. NET hosted client object model and Silverlight client object model. With the JavaScript Object Model, you can use objects without deploying code on the server. When you deploy a sandbox solution or use the server functional area, it can be very useful when processing objects on the client. Thanks to Javascript, all code is executed asynchronously and relies on callback functions to use objects within SharePoint Foundation 2010. Javascript can only process objects in the current context, that is, objects outside the current context cannot be accessed.

To minimize the server load, all object attributes are not loaded when an object is created. You must use the include statement and load (clientobject) (this link may point to an English page) function to request specific attributes.

JavaScript does not support attributes in the hosted client object model. The JavaScript Object Model uses the SET _ and get _ methods to publish relevant properties based on the ability to retrieve or set attribute values.

The following list shows the important debugging. js files installed in the/_ layouts Folder:

    • Sp. Debug. js
    • Sp. Core. Debug. js
    • Sp. ribbon. Debug. js
    • Sp. runtime. Debug. js
    • Jsgrid. Debug. js
    • Jsgrid. Gantt. Debug. js

 

V. Client object model namespace:

Microsoft. Sharepoint. Client is the core namespace used for. Net hosted object models and Silverlight object models,

SP is the core namespace used for ecmascript (JavaScript, JScript) object model.

The client object model and its corresponding collection objects inherit from the clientobject (javascript: clientobject) and clientobjectcollection (javascript: clientobjectcollection) classes.

In addition to the core namespace, Microsoft SharePoint Foundation 2010 also provides the following namespace:

The following table shows the equivalent objects that APIs of the Sharepoint client object model provide for common SharePoint Foundation 2010 server objects.

Apis of the Sharepoint client object model do not provide management objects or objects beyond the site collection scope, that is, spsite classes in the server object model.

 

6. Client context as the central object)

When programming using the server-side object model, we all know that there is a spcontext object. Similarly, the client Object Model of SharePoint uses the clientcontext object as the "gravity center" of all operations ".

When retrieving and using websites and data, you must first retrieve the context object. For example, clientcontext = new clientcontext ("http: // myserver/sites/mysitecollection") instantiates the context object of a specific website set.

The clientcontext object (javascript: clientcontext) serves as the main entry point for processing the client object model, and serves as the central object for centralized request and startup operations on the website. You can use the object attributes of the clientcontext object (javascript: clientcontext) to obtain the website set or website (through which other SharePoint Foundation client objects can be remotely accessed ).

 

The clientcontext () constructor (javascript: clientcontext (serverrelativeurl) initializes the client context based on the specified website or website set. In the Managed Client object model, this URL must be the absolute URL of a specific website. In the ecmascript (JavaScript, JScript) object model, either the relative URL of the server or no parameters are used. In JavaScript, if you use a constructor without any parameters, the URL of the target website is the URL of the website containing the webpage.

before the query is executed, you can use the objects returned by the client context to define the operations to perform. The clientcontext class (javascript: clientcontext) inherits load from the clientruntimecontext class (javascript: clientruntimecontext) (T, expression []) (javascript: load (clientobject) and loadquery () (javascript: loadquery (clientobjectcollection, exp) methods. Define a query to perform a specific operation and return a specific object or attribute, and then call a method to load the query.

After loading the query, call the executequery () or executequeryasync (response, clientrequestfailedeventhandler) method of the clientcontext object (javascript: executequeryasync (succeededcallback, failedcallback )) to send the query to the server. The Silverlight client object model provides an executequery () method (which can be synchronously called from threads that do not modify the user interface (UI) and an asynchronous executequeryasync (clientrequestsucceedeventhandler, clientrequestfailedeventhandler) method (used when the thread does not modify the UI ). These methods are used to execute queries. They represent the XML of the operations performed on the client and send the XML to the server. In the managed object model, this call is synchronized, indicating that the organization code is executed before the response from the server is received. This call can be synchronous or asynchronous in the Silverlight object model, while it is always asynchronous in the JavaScript Object Model. In asynchronous calls, the Code continues to be executed without waiting for the server to respond. In the Silverlight object model and JavaScript Object Model, callback functions can be called when a server response is received.

In SharePoint Foundation Silverlight and JavaScript Object Models, you can use the current property of the client context (javascript: Current) to return the current request context from the page running in SharePoint Foundation.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.