XML-RPC URL Domain Package for TclHTTPD
Description: XML-RPC package for Tcl. Provides remote procedure calls using the XML-RPC protocol over HTTP.
Keywords: Tcl,XML-RPC,SOAP,Simple Object Access Protocol,XML,tclHTTPD

| # Tcl XML-RPC Server Utility Package |
# This code has been superceeded as of version 1.6 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
    }
The result here is initially a string formatted in the iso8601 point in time format. As there is no real way for Tcl to distinguish between this string and a non-date string we have to provide a hint so that the XML-RPC reply has the correct type information. 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
    }
Here, we are returning an array of sorted elements. The type of each element will have to be guessed by the framework as the elements themselves are not TypedVariables. 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.