wiki:ExampleUsingXmlRpcCompliantTypes

Version 1 (modified by lauer, 17 years ago) (diff)

--

Using XML-RPC compliant types in your API

If ypu use types in your remote calls wich are XML-RPC compliant things are very easy:

Server side

  • The server side defines an API to be used remotely over XML-RPC. Additionaly an implementation of the API is hosted on the server-side

interface Api {
  String getStatusMessage( int code );
}

class Impl implements Api {
  public String getStatusMessage( int code ) {...}
}
  • register implementation as XML-RPC handler with the server
WebServer xmlRpcServer = new WebServer( port );
xmlRpcServer.addHandler( "handlerId", XmlRpcHandlerFactory.createHandlerFor( new Impl() );
xmlRpcServer.start();

Client side

  • create a remote client the use the API by simply calling a single method
Api remote_api = XmlRpc.createClient( Api.class, "handlerId", host, port );
String msg = remote_api.getStatusMessage( 42 );
...