Sunday, June 24, 2012

Client Side OM updated



in CSOM

we create a batch of commands and then fire them
at one go .helps increase  efficiency.

the server will process the task at on go and send the results back to the client

side..instead of one postback after another.

Communication is done send commands with XML ---> the result/response is returned  back with

JSON .

there is a free tool in u2u.be site which can be used for writing CAML queries.
SP.js is a  minified version  of SP.debug.js . In the debug mode the SP.debug.js is use
whereas the SP.js is used in the production version of the Sharepoint.

1>JSOm can be used for any used for any HTML  in the conrext of a sharepoint site
app/web page.
2>web Parts
3> Dialof framwork -- popup etc  in the browser.

You can use the JQuery that is there for SP site throgh the concept fo CSOM .
Here we get the context of the site  ctx(say).
then we use the
ctx.executequeryasynch(onSucces,onFail)


in jquery its always executequeryasynch as the UI is left un touched and the querying

happens asych without depending on whether postbacjk is happning or not.

onSucces,onFail methods are the ones that get called after the ctx has been able to or

unable to fire the query and fetch results .



------------------------------

inside the Sharepoint we get the file to be hosted  in the :

Jquery files can be uploaded and deployed at the physical file system

Virtaul FS (content db).
hence whenever we upload stuff using the web user interface like the SPD  its gets
loaded into the VFS.
scoped to the level of a site.Hence JQuery needs to be deployed at all the sites.
The advantage here the SandBox Sol can be used to deploy at this VFS.
without the need of a admin

Physical FS i.e /_layout/ folder -- Content  is palced on the  fron end serever at he
14 hive
c:/prog files/common files/microsoft shared /web server extesions/14/
hive
Here the JQuery can be placed once in the Phuscial file system and we can just reeference

the same frome verywhere else.

Choose between the two.

Custom Action is a small XML wrapped inside a feature that references JQuery .
Advantages : its a techniq that will work with SandBox sol/Office 365 in cloud etc.
 


=====================================

JSOM is intended for accessing and manipulating SharePoint objects by using JavaScript (ECMAScript) in an asynchronous fashion. It is very useful in situations where you want to access SharePoint data or make manipulations to the data after the page has been loaded on the client.

JSOM provides a comprehensive set of APIs that can be used to perform operations on most
SharePoint objects such as Site, Web, List, ContentTypes, User Permission and so forth. The API is simple to use and allows the developer to focus on the business scenario with a minimum amount of infrastructure required. JSOM fully supports JQuery and both can be used in conjunction with the other
SUPPORTED ON :
•Microsoft Internet Explorer 7.0 or greater

•Firefox 3.5 or greater
•Safari 4.0 and greater
The client object model acts as a proxy to connect to a WCF service (Client.svc) for the processing of the request. The Client.svc service is the protocol server responsible for performing all of the operations requested by the client object model. The service is located at /_vti_bin/client.svc on the server. The protocol server endpoint appends /_vti_bin/client.svc/ProcessQuery to process a request and requires a formatted Xml Request message based on the client protocol specifications.
Client.svc is an internal WCF service; it is reserved for SharePoint usage and is not intended to be used directly in client code. If you attempt to add a service reference to this service, no proxy will be generated. Internally, the Client.svc leverages the server-side object model to handle all client requests and return a JSON response.
The new ECMAScript (JavaScript, JScript), .NET managed, and Silverlight client object models each provide a subset of the server object model that is defined in Microsoft.SharePoint.dll, including objects that correspond to major objects at the site-collection level or lower in the SharePoint Foundation hierarchy. To improve security and performance, the client object models focus on the most relevant APIs for client-side development, and do not contain all the types and members that are represented in the server object model

 All operations are inherently asynchronous,and commands are serialized into XML and sent to the server in a single HTTP request. For every command, a corresponding server object model call is made, and the server returns a response to the client in compacted JavaScript Object Notation (or JSON) format, which the proxy parses and associates with appropriate objects.
\
===============================================
In SharePoint 2010 we can access all SharePoint List  via Restful Service.  Here is the URL to access List REST Service.
/_vti_bin/ListData.svc/
will give us all the list data.
http://win-m2ircoq6iqa:44119/_vti_bin/Listdata.svc/Sreenicontacts ( REST Query to get all Contacts from SharePoint List called SreeniContacts.)
The Below screenshots shows my site Lists REST Service Entities.  
-----------------------------------------------
Connecting and displaying WCF service data as External List in the sp site
---------------------------------------------------------------------
BDC  ----
Client O Model :
Before actually executing a query, you use the objects that are returned through the client context to define the actions to perform. The ClientContext class (JavaScript: ClientContext) inherits the Load<T>(T, Expression<Func<T, Object>>[]) (JavaScript: load(clientObject)) and LoadQuery() (JavaScript: loadQuery(clientObjectCollection, exp)) methods from the ClientRuntimeContext class (JavaScript: ClientRuntimeContext). You define a query to perform specific actions and return specific objects or properties, and then you call one of these methods to load the query.
After you load a query, call the ExecuteQuery() or ExecuteQueryAsync(ClientRequestSucceededEventHandler, ClientRequestFailedEventHandler) method (JavaScript: executeQueryAsync(succeededCallback, failedCallback)) of the ClientContext object (JavaScript: ClientContext) to send the query to the server. The Silverlight client object model provides both an ExecuteQuery() method, which can be called synchronously from threads that do not modify the user interface (UI), and an asynchronous ExecuteQueryAsync(ClientRequestSucceededEventHandler, ClientRequestFailedEventHandler) method for cases where threads do modify the UI. These methods for executing queries formulate XML that represents the actions taken on the client, and send the XML to the server.
  • In the managed object model, this call is synchronous, which means that code execution is blocked until a response is received from the server.
  • This call can be either synchronous or asynchronous in the Silverlight object model,
  • but it is always asynchronous in the JavaScript object model.
  • In an asynchronous call, code continues to execute and does not wait for the server response.

In the Silverlight and JavaScript object models, you can implement a callback function that is invoked when the server response is received.
 

Data Query in the client object model ;
Two points to keep in mind when using LINQ to query against the client object model:
  • When you use LINQ to create queries against the client object model, you are using LINQ to Objects, not the LINQ to SharePoint provider, which can only be used when you write code against the server object model.
  • When your query is designed to return a subset of list items from a list, it is more efficient to use a CAML query than a LINQ query. This is because all the list items are sent from the content database to the front-end web server and loaded into memory. Only then is the LINQ filter is applied. With a CAML query, the filtering is done on the database server. This point applies only to queries that filter the items on a list. Other kinds of LINQ queries, such as returning a subset of the lists from a web site, are more efficient.
 Note 

Two points to keep in mind when using LINQ to query against the client object model:
When you use LINQ to create queries against the client object model, you are using LINQ to Objects, not the LINQ to SharePoint provider, which can only be used when you write code against the server object model.
When your query is designed to return a subset of list items from a list, it is more efficient to use a CAML query than a LINQ query. This is because all the list items are sent from the content database to the front-end web server and loaded into memory. Only then is the LINQ filter is applied.
With a CAML query, the filtering is done on the database server. This point applies only to queries that filter the items on a list. Other kinds of LINQ queries, such as returning a subset of the lists from a web site, are more efficient. 

No comments:

Post a Comment