3. SOAP::Lite for Perl
This section shows you how to write a SOAP client using SOAP::Lite for Perl. The instructions given here pertain to Win32 and Unix systems but can be adapted for any applicable platform.
You can of course incorporate the perl code you find here into CGI Web Pages but it is not our intention to provide examples of that here because the SOAP-related code that you would incorporate is essentially invariant. As such we will just look at the bare essentials in a stripped down client with the rawest user interface possible.
As is the case when writing clients to any SOAP service, ensure in advance that you are familiar with the service and its method signatures.
We will build three clients, one for each service method.
Installing Perl and the required Perl Modules [ for Win32 ]
By far the easiest way to install everything you need is to start afresh (ie. with no prior Perl installation) and install the latest version of ActivePerl (5.6.1 or later) from ActiveState.com. To do this, simply go to their download area, choose the Windows/MSI package and save it to your machine. You will then have a Microsoft Installer (msi) file called ActivePerl-184.108.40.2068-MSWin32-x86-multi-thread.msi (version number may change).
If you cannot start afresh because you already have ActivePerl installed and it is a version prior to 5.6.1 or you have another kind of Perl installation then you can try one of the following:
Launch the installer by double clicking on the downloaded msi file. Follow the instructions to install ActivePerl on your machine. If you accept all the defaults then everything will be installed to C:/Perl (other destination directories are fine but just note that the paths mentioned below are based on the default).
Fortunately, this installation includes all of the Perl Modules required for writing Perl clients that exploit SOAP::Lite for Perl. To verify that you have got all the required modules, open up a command window and run the Perl Package Manager (PPM) with the following command (note that you will need to be connected to the internet for this to work).
> ppmYou should see the following (version numbers may change):
PPM interactive shell (2.1.5) - type 'help' for available commands PPM>If that is not the case then you will need to check the ActivePerl documentation that you downloaded with ActivePerl and go to Active Perl FAQ / Using PPM.
Once PPM is working, type the following command to view the list of installed packages:
PPM> queryYou should get a list that looks like the following (version numbers might change). The packages shown in bold are the ones you must have for SOAP::Lite to work. If they are missing from your list then you will have to search for and install them - this can be done using PPM (just type search followed by the package name (to ensure that it is available), then install followed by the packagename to download and install it - see the ActivePerl documentation (Active Perl FAQ / Using PPM / How do I use PPM?) for more detail.
Archive-Tar [0.072 ] module for manipulation of tar archives. Compress-Zlib [1.08 ] Interface to zlib compression library Digest-MD5 [2.11 ] Perl interface to the MD5 Algorithm File-CounterFile [0.12 ] Persistent counter class Font-AFM [1.18 ] Interface to Adobe Font Metrics files HTML-Parser [3.19 ] SGML parser class HTML-Tagset [3.03 ] Data tables useful in parsing HTML HTML-Tree [3.11 ] HTML syntax tree builder MIME-Base64 [2.11 ] Encoding and decoding of base64 strings PPM [2.1.5 ] Perl Package Manager: locate, install, upgrade software packages. SOAP-Lite [0.46 ] Library for Simple Object Access Protocol (SOAP) clients and servers in Perl URI [1.11 ] Uniform Resource Identifiers (absolute and relative) XML-Parser [2.27 ] A Perl module for parsing XML documents libnet [1.07.03] Collection of Network protocol modules libwin32 [0.17.2 ] A collection of extensions that aims to provide comprehensive access to the Windows API. libwww-perl [5.51 ] Library for WWW access in Perl
That completes the Win32 installation. If you do not want to install Perl and the required Perl Modules on a Unix system as well, you can skip the following and go directly to Understanding the Client Code .
Installing Perl and the required Perl Modules [ for Unix ]
Once perl is installed you will also need to install the following packages. The versions shown are not strictly required although these are the versions that we have tested and confirmed so we do recommend you use these versions or later. If you are not experienced with Perl Module installation then please read the installation notes below before you start.
Installation notes : installing perl modules can be a little tricky - here are a few tips to help you avoid or get you over at least some of the obstacles. The internet abounds with FAQs for the many potential hazards not covered here.
Understanding the Client Code
Writing the Clients
Note that the perl scripts shown here presume that you have the Quotation Service running on your machine (at localhost:8080). If this is not the case then you can run the clients against our demo SOAP server. To do this simply replace localhost:8080 with services.xmethods.net in the above script. For more information on our demo server, refer to the Demo Section .
Running the Clients
> perl getAllQuotations.pl > perl submitQuotation.pl > perl getAllQuotations.pl > perl getQuotationsByAuthor.plThe first call should result in a list of quotations (at least two entries), the second has no result but its success is evidenced by the following call to getAllQuotations which should show the same list plus the quotation by John F. Kennedy (unless it was already in the list). The last call should give you just those quotations by Oscar Wilde.
That's all there is to it for clients using SOAP::Lite for Perl. Next we will look at clients written with the Microsoft SOAP Toolkit.
[ Nicholas Quaine ]
Copyright © 2001-2007 Nicholas Quaine. All rights reserved.