Skip to content
This repository has been archived by the owner on Jan 16, 2019. It is now read-only.

Docs JsonRpc SMD

Frank Kleine edited this page Apr 7, 2012 · 1 revision

Integrating Stubbles with other client frameworks

The Stubbles JSON-RPC processor supports the generation of Simple Method Descriptions (SMD) to ease the integration with the DOJO Toolkit.

SMD is for JSON-RPC, what WSDL is for SOAP. An SMD file describes the methods a JSON-RPC service provides and gives detailed information about these methods. Generating an SMD file for any service that you export via the Stubbles JSON-RPC processor is easy, you only need to append __smd=$SERVICENAME to the processor URL.

The generated SMD file for the MathService from the example will look like this:

{"SMDVersion":1,"serviceType":"JSON-RPC","serviceURL":"\/\/localhost\/pathtoprocessor\/jsonrpc.php?processor=jsonrpc&__class=MathService","methods":[{"name":"add","parameters":[{"name":"a"},{"name":"b"}]}],"objectName":"MathService"}

For a detailed description refer to the DOJO website.

Using Dojo as a client framework

Integrating the DOJO toolkit is very easy, you only need to add the following javascript code to your HTML page:

<script type="text/javascript" src="http://o.aolcdn.com/dojo/0.9.0/dojo/dojo.xd.js"></script>

<script type="text/javascript">
djConfig.usePlainJson = true;
dojo.require('dojo.rpc.JsonService');

var proxy;
function setup() {
  var smdURL = '/path/to/service.php?processor=jsonrpc&__smd=MathService';
  proxy = new dojo.rpc.JsonService(smdURL);
}
dojo.addOnLoad(setup);
</script>

The first <script/> tag loads the core of the DOJO toolkit. Using the dojo.require() method, you have to load the JSON-RPC proxy component of DOJO, which is able to create Javascript proxy objects from any SMD file. The proxy is created by creating a new instance of dojo.rpc.JsonService and passing the URL which creates the SMD file.

You can now call the service methods on this proxy, as if it they were part of the proxy class:

proxy.add(25, 17).addCallback(calcCallback);

function calcCallback(result) {
  alert(result);
}

The calcCallback method will be called after the server returned the JSON-RPC response. For more information on the JSON-RPC proxies provided by Dojo, refer to the DOJO documentation.

Clone this wiki locally