Writing a CGI-based Server
Here's a simple CGI-based SOAP server:
1.a. server (hibye.cgi)
#!perl -w
use SOAP::Transport::HTTP;
SOAP::Transport::HTTP::CGI
-> dispatch_to('Demo')
-> handle;
package Demo;
sub hi {
return "hello, world";
}
sub bye {
return "goodbye, cruel world";
}
There are basically two parts to this: the first four lines set up a SOAP wrapper around a class. Everything from 'package Demo' onward is the class being wrapped.
In the previous version of the SOAP specification (1.0), SOAP over HTTP was supposed to use a new HTTP method, M-POST. In practice, there are many web servers that don't understand the M-POST method so this requirement was weakened and now it's common to try a normal POST first and then use M-POST if the server needs it. If you don't understand POST and M-POST, don't worry, you don't need to know all about it to use the module.
Writing a Client
This program prints the results of the hi() method call:
1.a. client (hibye.pl)
#!perl -w
use SOAP::Lite;
print SOAP::Lite
-> uri('http://www.gnulamp.com/Demo')
-> proxy('http://soap.gnulamp.com/hibye.cgi')
-> hi()
-> result;
The uri() identifies the class on the server, and the proxy() identifies the CGI script that provides access to the class. Since both look like URLs, I'll take a minute to explain the difference, as it's quite important.
proxy()
proxy() is simply the address of the server to contact that provides the methods. You can use http:, mailto:, even ftp: URLs here.