I have been testing out using SOAP from Tcl and have come up with the following package to provide Tcl commands for SOAP remote procedure calls. The following code demonstrates the ease of use for simple RPC calls. This is a work in progress and some parts need more work. In particular the transport layer needs to be able to be configured to cope with proxy HTTP servers and authenticating proxys and the like. Still it may be usefull as-is.
This example connects the Tcl procedure getTemp to the remote method hosted by XMethods. In all these examples Tcl commands are prefixed with the % character that is my prompt under tclsh. Results are printed without the preceeding prompt character.
% package require SOAP
1.5
% SOAP::create getTemp \
-uri "urn:xmethods-Temperature" \
-proxy "http://services.xmethods.net/soap/servlet/rpcrouter" \
-params { "zipcode" "string" }
::getTemp
% getTemp 90810
41.2
|
We bring in the package and then define the method. The configuration requires a URI for the XML namespace of the SOAP method and a URL for the service. The params configure option allows the Tcl procedure to do simple parameter checking without passing duff packets over the network.
Another example, this time using the extremely clever SOAP::Lite Perl package as a server, a Celcius to Fahrenheit convertor. We shall test it using that peculiar temperature -40. This time I want the Tcl procedure to be called C2F.
% package require SOAP
1.5
% SOAP::create C2F \
-uri "http://www.soaplite.com/Temperatures" \
-proxy "http://services.soaplite.com/temper.cgi" \
-params { "temp" "float"}\
-name c2f
::C2F
% C2F -40.0
-40
%
|
It will be possible to use different transport protocols to transfer the SOAP packets. At this time only HTTP is supported. You may need to configure the transport subsystem so the SOAP::configure command has a -transport option. For example, at work I live behind a Microsoft NT firewalling proxy web server. So I need to tell the SOAP transport about the proxy. This is an authenticating proxy, so I have to add a header to all HTTP requests using the Proxy-Authorization HTTP field. Here's how I set up my system and then create a command for the SOAP::Lite languages method.
% package require SOAP
1.5
% SOAP::configure -transport http -proxy proxyhost:8080 \
-headers { "Proxy-Authorization" "Basic dXNlcm5hbWUgOiBwYXNzd29yZA==" }
% SOAP::create languages \
-uri "http://www.soaplite.com/Demo" \
-proxy "http://services.soaplite.com/hibye.cgi" \
-params {}
::languages
% languages
Perl sh C
%
|
To setup a method to use a different transport there is a -transport option for the method configure command. This should be set to the name of a procedure that will be called with the URL of the SOAP service and the XML data of the SOAP request. It should return the reply packet or error. For example, I have a dummy transport procedure that prints the SOAP request and doesn't send it anywhere. To see what is being generated for a method:
# A dummy SOAP transport procedure to examine the SOAP requests generated.
proc SOAP::transport_print { url soap } {
puts "$soap"
return {}
}
% SOAP::configure languages -transport SOAP::transport_print
::languages
% languages
<?xml version='1.0'?>
<SOAP-ENV:Envelope
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Body>
<ns:languages xmlns:ns="http://www.soaplite.com/Demo" />
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
%
|
For debugging purposes it can be useful to see the XML that was generated for the SOAP method request at each end. The SOAP::dump command will return the XML for the last transaction using HTTP for a named method.
Create a Tcl binding for a remote procedure call using SOAP. See configure for the permitted options.
Used for global configuration of the available transports. The options passed in to this command are dependent on the transport mchanism. The only transports currently available
The HTTP transport may require a proxy server and possible other headers to be included. This is where to add this information. For example, to pass an authenticating proxy server I need to provide the name of the server and a Proxy-Authorize HTTP header using the Trf package to provide the base64 encoding procedure.
SOAP::configure -transport http -proxy wwwproxy:8080 \
-headers { "Proxy-Authorize" "Basic [base64 -enc user:pass]" }
SOAP::configure getTemp -params { "zipcode" "string" }
SOAP::configure c2f -params { "temperature" "float" }
SOAP::configure hi -params {}
proc my_reply_hook { methodName xml } {
puts "$xml"
return $xml
}
proc gotInfo {window data} { ... }
SOAP::configure getInfo -command {gotInfo .frame1.edit} ...
Retrieve a configuration value from the method. The
optionName should be one of those listed for
configure. There is one additional read-only value to be
obtained:
Returns information about the last HTTP transaction.
Make a SOAP call to the configured server. This is not expected to be called by a user but is called by the Tcl command procedure for this SOAP method.
This command presents a dialog box used to configure the SOAP package to work with a proxy server. The fields are used to call SOAP::configure -transport http with the relevant options. The first entry field takes the name and port of the proxy server (eg: webproxy:8080) and the second two fields are used to configure a Basic Authentication HTTP header allow operation with an authenticating proxy. (ie: an NT IIS server).
The package can be downloaded from the SourceForge project site at SourceForge or from the SourceForge anonymous FTP site at ftp://tclsoap.sourceforge.net/pub/tclsoap/TclSOAP-1.5.1.tar.gz . This file should be unpacked somewhere handy and you should set your TCLLIBPATH environment variable to suit. For windows users, you may as well unpack it to Program Files\Tcl\lib\tcl8.3
The source is spread over the following files. These files have all been htmlized so if you want to use them, rather than just look at them, get and unpack the tar.gz distribution.
This site is hosted by SourceForge.
Last modified: Mon Jun 25 01:28:53 BST 2001