To communicate with a remote XML-RPC service, first create a proxy object with:
where <url> is the services' http-url. Typically something like
"http://bleu.west.spy.net/geo/RPC2" or "http://www.xmlrpc.com/RPC2".
proxy := XMLRPC::XMLRPCProxy withUrl:<url>
Once created, a call is performed with:
For calls without arguments you can also use "
retVal := proxy invokeMethod:<nameOfMethod> withArgs:<arrayOfArgs>.
invokeMethod:<nameOfMethod>
".
XML-RPC only supports a limited set of supported datatypes both as argument and as return value. These are:
|jira issue sessionKey|
jira := XMLRPC::XMLRPCProxy withUrl:'http://localhost:8081/rpc/xmlrpc'.
sessionKey := jira invokeMethod:'jira1.login' with:userName with:password.
issue := Dictionary new
at:'project' put:'projectKey';
at:'type' put:1;
at:'summary' put:'Issue created via XMLRPC';
at:'assignee' put:'responsibleUserName';
at:'description' put:'Created with an ST/X client';
yourself.
jira invokeMethod:'jira1.createIssue' with:sessionKey with:issue.
jira invokeMethod:'jira1.logout' with:sessionKey.
httpServer := HTTPServer serverOnPort:8080.
then, an XML-RPC service has to be instantiated for that server:
xmlrpcService := XMLRPC::XMLRPCService new.
xmlrpcService linkName:'/xmlrpc'.
xmlrpcService registerServiceOn:httpServer.
To support the XML-RPC introspection interface
(listMethods, methodHelp and methodSignature), use:
xmlrpcService enableIntrospectionProtocol.
Finally, you must register the methods which can be called.
For example, to arrange for
the rpc-message "demo.foo
" with a string argument to be attached to the
"DemoClass foo:
"-method,
execute the following setup:
xmlrpcService
registerMethod: 'demo.foo'
help:'Invoke the foo method of the Demo class'
signature:#('string' 'string')
receiver: DemoClass
selector: #foo:
Assuming, that the foo: methods code is:
foo: params
|arg|
arg := params first.
^ arg asUppercase
Of course, a common strategy would be to subclass XMLRPCService,
and perform the above registration in its #initialize
method.
at:
and size
messages
and can therefore used like an argument-vector. However, it also provides a reference to the
original HTTP-request (via the request
method).
This information might be used for authentication or statistics.
server := XMLRPC::XMLRPCProxy withUrl:'http://localhost:8081/rpc/xmlrpc'.
(server invokeMethod:'system.listMethods') do:[:eachMethodName |
Transcript showCR:eachMethodName.
Transcript showCR:((server invokeMethod:'system.methodHelp' with:eachMethodName).
].
Copyright © 2010 eXept Software AG
<info@exept.de>