SOAP Web Service Tutorials - Herong's Tutorial Examples - Version 5.01, by Dr. Herong Yang
SoapTcpClient.pl - SOAP Client Example with TCP Protocol
This section provides a tutorial example on how to use the SOAP::Lite module to create a SOAP client program, SoapTcpClient.pl, with the TCP protocol.
SOAP:Lite represents the SOAP client API that allows you to send a Perl function call as a SOAP request to the specified SOAP server, and receive the result of the call as a SOAP response from the server. Main functions of SOAP::Lite are:
new() - Constructs a new SOAP::Lite object, and returns it.
uri('uri') - Defines the URI (Universal Resource Identifier) of the target module to be called, and returns the same object.
proxy('url') - Defines the URL (Universal Resource Locator) of the SOAP server, and returns the same object.
'method'() - Allows to call the method from the target module on the SOAP server, and returns a new SOAP::SOM object representing the outcome of the call.
$som->result - A property of a SOAP::SOM object representing the returning scalar value of the call.
Here is a sample program to show you how to use SOAP::LITE module to request a function call to the SOAP server I created in the previous section.
#- SoapTcpClient.pl #- Copyright (c) 2002 by Dr. Herong Yang, http://www.herongyang.com/ use SOAP::Lite; # use SOAP::Lite +trace; my $client = SOAP::Lite->new(); $client->uri('urn:Hello'); $client->proxy('tcp://localhost:8001'); my $som = $client->hello("Herong"); my $output = $som->result; print $output . "\n";
Run it while the SoapTcpServer.pl is running, you will get:
This is amazing. You can create a simple SOAP server and client in less than 20 lines of source code!
Note that the proxy URL must have "tcp" as the protocol name, since the SOAP server is running with TCP as the transportation protocol.
Last update: 2007.
Table of Contents