You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 8 Next »

Unable to render {include} The included page could not be found.
Unable to render {include} The included page could not be found.

<binding.ajax>

Tuscany supports web browser clients using AJAX to communicate with with SCA components by using the <binding.ajax> SCDL extension. This enables remote web browser clients to easily make RPC style calls to server-side SCA components and for server-side SCA components to easily make COMET / Reverse Ajax style requests to the web browser.

This binding has no attributes or elements so to include it on a SCA service or reference simply requires the following SCDL:

   <binding.jsonrpc/>

Also see <binding.jsonrpc which provides some similar function.

Any JSON-RPC client may be used to access SCA services which use <binding.jsonrpc>, but to simplify the task for web browsers the binding can generate a script which may be included within an HTML document to set up proxy objects for each SCA service within the HTML page environment.

This script is used by simply including the following script tag within the HTML page:

    <script type="text/javascript" src="SCA/SCADomain/scaDomain.js" />

This initializes the proxys for the SCA services which can then be used make requests to the server-side components. For example, if there was a service named "myService" using <binding.ajax> which had operations "aOnewayRequest" and "anRpcRequest" the scripts in the HTML page could now invoke these opperations with the following:

myService.aOnewayRequest(args);

or

myService.anRpcRequest(args, responseFunction);

In the that example 'responseFunction' is the name of a function which is called to process the response and which gets called asynchronously on another thread when the response is avaialble. RPC requests are done this way instead of the simpler "answer = myService.anRpcRequest(args)" to avoid hanging the browser while the (potentialy slow) request is being processed. An example of the responseFunction for the previous example is:

function responseFunction(answer){
  // do something with answer
}

For SCA references using <binding.ajax> a function needs to be written to handle each operation that may be called by the reference. The operations used by the reference cannot return any response but must be one-way style operations. As an example, if there is an SCA reference named "myReference" which has an operation named "foo" then the client side function required would be:

myReference.foo = function(args) {
  // do something with args
}

SCA references using <binding.ajax> require a communication channel between the server-side Tuscany runtime and the remote web browser client. This channel can be explicitly opened and closed by the client, and it must be opened before any client side function assoicated with a SCA reference will be invoked. This is done with:

scaDomain.open();

and

scaDomain.close();

The connection is automatically closed when the web page is closed so if the client does not need fine grain control the 'onLoad' of the HTML body element can be used to establish the connection, for example:

<body onLoad="scaDomain.open()">

Some examples:

Differences between <binding.jsonrpc> and <binding.ajax>

The current Tuscany SCA runtime supports <binding.jsonrpc> and <binding.ajax> which provide similar functionality. The differences are:

  • <binding.jsonrpc> supports the SMD protocol enabling easy use with Dojo, <binding.ajax> does not support SMD
  • <binding.ajax> supports SCA references and using COMET style asynchronous operation, <binding.jsonrpc> does not

These differences should be resolved by the Tuscany SCA 1.0 release.

  • No labels