Tuscany supports JSON-RPC as a protcol for use with SCA services by using the <binding.jsonrpc> SCDL extension. This enables remote web browser clients to easily make RPC style calls to server-side SCA components.
This binding has no attributes or elements so to include it on a SCA service simply requires the following SCDL:
Also see <binding.ajax 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:
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" which had operations "aOnewayRequest" and "anRpcRequest" the scripts in the HTML page could now invoke these opperations with the following:
In 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:
Using SCA JSON-RPC services with Dojo
Apache Tuscany JSON-RPC services provide built-in support for Dojo RPC. The Dojo toolkit is a popular framework for writing Ajax/Web 2.0 style browser client applications. Tuscany SCA services which use <binding.jsonrpc> will by default support the Simple Method Description (SMD) protocol. SMD is similar to ?wsdl for Web services, entering a service endpoint appended with ?smd will return a SMD descriptor for the service.
Using Tuscany SCA services with Dojo can therefore be as simple as the following:
var myService = new dojo.rpc.JsonService("SCA/SCADomain/myService?smd");
|Changes since 0.90 release|
The Tuscany JSON-RPC and Ajax binding's have had significant functional and useability changes since the 0.90 release. It is recomended that if possible the latest code is used (the description on this page is based on the latest code).