This section provides a tutorial example on how to use the SOAP::Transport::HTTP module to create a SOAP server with the HTTP protocol.
The SOAP::Transport::HTTP::Daemon module is very similar to the SOAP::Transport::TCP::Server
module. It offers two functionalities: 1. Taking SOAP requests as a SOAP server;
2. Interacting with application modules to handle the requests as a SOAP server side
API.
The SOAP::Transport::HTTP::Daemon module supports the same methods as the
SOAP::Transport::TCP::Server module. See the previous chapter for details of those
mothods.
Here is a sample program to show you how to create a SOAP server with HTTP as the
transportation protocol and dispatch SOAP requests to application modules:
#- SoapHttpServerTrace.pl
#- Copyright (c) 2002 by Dr. Herong Yang, http://www.herongyang.com/
use SOAP::Lite +trace;
use SOAP::Transport::HTTP;
my $daemon = SOAP::Transport::HTTP::Daemon
-> new (LocalAddr=>'localhost', LocalPort=>8001, listen=>5);
$daemon -> dispatch_to('Hello::hello');
print "Contact SOAP server at ", $daemon->url, "\n";
$daemon->handle();
To test the server, you need a SOAP client program that can talk to the server using
HTTP protocol. Here is a sample code:
#- SoapHttpClientTrace.pl
#- Copyright (c) 2002 by Dr. Herong Yang, http://www.herongyang.com/
use SOAP::Lite +trace;
my $client = SOAP::Lite->new();
$client->uri('urn:Hello');
$client->proxy('http://localhost:8001');
my $som = $client->hello("Herong");
my $output = $som->result;
print $output . "\n";
Notice that this client program is the same as the client program that talks to
the server using TCP protocol, except the prefix code in the server URL. See
the "proxy('http://localhost:8001')" function call.
Now run the server program first, then run the client program in a different command
window. You should get the following output in the client program window: