2016/05/28 - Apache Tuscany has been retired.

For more information, please explore the Attic.

 Apache Tuscany > Home > SCA Overview > SCA Java > Java SCA Documentation Menu > SCA Java binding.ajax User List | Dev List | Issue Tracker  


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 web browser clients.

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


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

In order for a web browser client to interact with SCA services and references which use <binding.ajax> it needs to included a Tuscany runtime scaDomain.js script which will initialize the SCA enviroment and provides control functions. This script is dynamically generated to include

A web browser client needs to include a Tuscany runtime system script in its HTML page before it can interact with SCA services and references which use <binding.ajax>. This is done by simply including the following script tag within the HTML page:

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

This creates proxy objects 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.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:




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:

See the chat-webapp sample in the Tuscany SCA samples folder for an example of using <binding.ajax>

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
  • <binding.jsonrpc> uses the standard JSON-RPC protocol, <binding.ajax> uses a proprietry protocol using DWR

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

website stats