This chapter describes:
- Introduction to SOAP::Transport::HTTP::Daemon module, and sample programs.
SOAP::Transport::HTTP::Daemon Module
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
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
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:
SOAP::Transport::new: () SOAP::Serializer::new: () SOAP::Deserializer::new: () SOAP::Parser::new: () SOAP::Lite::new: () SOAP::Transport::HTTP::Client::new: () SOAP::Lite::call: () SOAP::Serializer::envelope: () SOAP::Serializer::envelope: hello Herong SOAP::Data::new: () SOAP::Data::new: () SOAP::Data::new: () SOAP::Data::new: () SOAP::Data::new: () SOAP::Transport::HTTP::Client::send_receive: HTTP::Request=HASH(0x25c5 a60) SOAP::Transport::HTTP::Client::send_receive: POST http://localhost:800 1/ Accept: text/xml Accept: multipart/* Content-Length: 500 Content-Type: text/xml; charset=utf-8 SOAPAction: "urn:Hello#hello" <?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-EN C="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle=" http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://sche mas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/1999/XMLS chema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema"><SOAP-ENV :Body><namesp1:hello xmlns:namesp1="urn:Hello"><c-gensym3 xsi:type="xs d:string">Herong</c-gensym3></namesp1:hello></SOAP-ENV:Body></SOAP-ENV :Envelope> SOAP::Transport::HTTP::Client::send_receive: HTTP::Response=HASH(0x24b 017c) SOAP::Transport::HTTP::Client::send_receive: HTTP/1.1 200 OK Date: Sat, 28 Dec 2002 17:15:01 GMT Server: libwww-perl-daemon/1.24 Content-Length: 522 Content-Type: text/xml; charset=utf-8 Client-Date: Sat, 13 Mar 2004 17:15:01 GMT Client-Peer: 127.0.0.1:8001 SOAPServer: SOAP::Lite/Perl/0.51 <?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-EN C="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle=" http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://sche mas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/1999/XMLS chema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema"><SOAP-ENV :Body><namesp1:helloResponse xmlns:namesp1="urn:Hello"><s-gensym3 xsi: type="xsd:string">Hello Herong</s-gensym3></namesp1:helloResonse></SOA P-ENV:Body></SOAP-ENV:Envelope> SOAP::Deserializer::deserialize: () SOAP::Parser::decode: () SOAP::SOM::new: () Hello Herong SOAP::Lite::DESTROY: () SOAP::Serializer::DESTROY: () SOAP::Data::DESTROY: () SOAP::Data::DESTROY: () SOAP::Data::DESTROY: () SOAP::Data::DESTROY: () SOAP::Data::DESTROY: () SOAP::Transport::DESTROY: () SOAP::Transport::HTTP::Client::DESTROY: () SOAP::SOM::DESTROY: () SOAP::Deserializer::DESTROY: () SOAP::Parser::DESTROY: ()
You should get the following in the server program window:
SOAP::Serializer::new: () SOAP::Deserializer::new: () SOAP::Parser::new: () SOAP::Server::new: () SOAP::Transport::HTTP::Server::new: () SOAP::Transport::HTTP::Daemon::new: () Contact SOAP server at http://localhost:8001/ SOAP::Server::handle: () SOAP::Deserializer::deserialize: () SOAP::Parser::decode: () SOAP::SOM::new: () SOAP::Data::new: () SOAP::Data::DESTROY: () (eval): Herong SOAP::Server::handle: Hello Herong SOAP::Serializer::envelope: () SOAP::Serializer::envelope: helloResponse Hello Herong SOAP::Data::new: () SOAP::Data::new: () SOAP::Data::new: () SOAP::Data::new: () SOAP::Data::new: () SOAP::SOM::DESTROY: ()
A couple of the interesting things to note here:
- The SOAP XML request is delivered as a true HTTP request using the POST method.
- The HTTP request as an extra header line: SOAPAction: "urn:Hello#hello".
- The SOAP XML response is delivered as a true HTTP response with a couple of extra header lines.
discuss this topic to forum
