The XMLRPC::Domain package provides a wrapper enabling the simple use of Tcl procedures as XML-RPC methods. This package is almost identical to the SOAP::Domain package as can be seen by the following example of the square method, here implemented over XML-RPC instead of SOAP:
package require XMLRPC::Domain
XMLRPC::Domain::register -prefix /rpc -namespace zsplat::RPC
proc zsplat::RPC::/square {num} {
if { [catch {expr $num + 0}] } {
error "parameter num must be a number"
}
return [expr $num * $num]
}
|
The only significant difference between the XMLRPC and the SOAP Domain packages is that the XML-RPC version supports a method for providing hints to the framework about the type of the result of the users procedure. Here is an example of a procedure that returns an XML-RPC dateTime.iso8601 result:
package require XMLRPC::TypedVariable
proc zsplat::RPC::/time {} {
set result [clock format [clock seconds] -format {%Y%m%dT%H:%M:%S}]
set result [XMLRPC::TypedVariable::create dateTime.iso8601 $result]
return $result
}
|
For simple types: int, double, string the framework can guess the correct type. For other types, you will need to return a TypedVariable as the result.
A more significant example of this is a method returning an array:
proc zsplat::RPC::/sort {args} {
eval set n $args
set result [lsort $n]
set result [XMLRPC::TypedVariable::create array $result]
return $result
}
|
XML-RPC supports struct results as well as arrays. This is supported from Tcl as Tcl arrays. The struct element name is set from the array element name.
For more details about writing services look at the SOAP::Domain documentation.
This site is hosted by SourceForge
Last modified: Fri Jun 8 22:33:25 BST 2001