SOAP::Transport::HTTP - SOAP Server with HTTP Protocol

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:

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:

Last update: 2007.

Table of Contents

 About This Book

 Introduction to Web Service

 Introduction to SOAP (Simple Object Access Protocol)

 SOAP Message Structure

 SOAP Message Transmission and Processing

 SOAP Data Model

 SOAP Encoding

 SOAP RPC Presentation

 SOAP Properties Model

 SOAP Message Exchange Patterns

 SOAP HTTP Binding

 SOAP Perl Implementations

 SOAP PHP Implementations

 SOAP Java Implementations

Perl SOAP::Lite - SOAP Server-Client Communication Module

 What Is SOAP?

 What Is SOAP::Lite?

 SOAP::Transport::TCP::Server - SOAP Server with TCP Protocol

 SoapTcpClient.pl - SOAP Client Example with TCP Protocol

 SOAP::Lite Tracing Functions

SOAP::Transport::HTTP - SOAP Server with HTTP Protocol

 Perl Socket Test Program for HTTP and SOAP

 Perl SOAP::Lite for GetSpeech SOAP 1.1 Web Service

 Perl SOAP::Lite 0.710 for SOAP 1.2 Web Services

 Perl SOAP::Lite 0.710 for WSDL

 PHP SOAP Extension Client Programs

 PHP SOAP Extension Server Programs

 Java Socket and HttpURLConnection for SOAP

 SAAJ - SOAP with Attachments API for Java

 SoapUI - SOAP Web Service Testing Tool

 WS-Security - SOAP Message Security Extension

 WS-Security X.509 Certificate Token

 Web Services and SOAP Terminology

 References

 PDF Printing Version