XMethods
Service List · Forums · About XMethods · Getting Started · Resources · Mailing List · Add a Service · Notes
Getting Started

SOAP::Lite for Perl, by Paul Kulchenko, is an oustanding SOAP implementation for Perl.

The following instructions focus on helping you get the SOAP::Lite implementation up and running, allowing you to easily bind to SOAP methods using Perl. Once you get the environment up and running, read our primer on writing SOAP clients to start using services.


A Quick-Start Guide for Installing SOAP::Lite for Perl

Step 1. Install Perl
Step 2. Install SOAP::Lite for Perl and supporting modules
    You can download the latest version of SOAP::Lite for Perl from the SOAP::Lite for Perl homepage, and the required supporting modules from CPAN. The SOAP::Lite homepage has excellent instructions for what modules need to be downloaded, with convenient links to the CPAN registry.

    Note that if you are using ActiveState's ActivePerl distribution, the only module you need to install is SOAP::Lite . All other modules are already installed as part of the distribution.

    Each of these modules installs using the typical Perl module installation procedure:

    1. perl Makefile.pl
    2. make
    3. make test
    4. make install

Note that an even easier alternative exists: Use the CPAN auto-install modules if you have CPAN.pm installed, while you are connected to the Internet. This is also detailed on Paul's SOAP::Lite homepage.


Writing a Client using SOAP::Lite for Perl

Writing a SOAP Client using the SOAP::Lite package for Perl is very simple. This tutorial walks you through a simple client that accesses the PING service hosted at http://www.xmethods.net

The following line imports the SOAP::Lite package for use by the client.

    use SOAP::Lite;
The following line executes the SOAP invocation in one easy step and sets the response object to $response :
    $response = SOAP::Lite
    -> proxy("http://services.xmethods.com/perl/soaplite.cgi")
    -> uri("urn:xmethodsPing")
    -> pingHost ("www.yahoo.com");

"Proxy" is the SOAP Endpoint
"URI" is the namespace identifier for the Interface / Object
"pingHost" is the method itself.
"www.yahoo.com" is the string argument for the pingHost method.

When this line is executed, the library encodes the method parameters by autodetecting type and assigning a system-generated name to this parameter (for basic types like "string" or "integer" , most server implementations ignore the input parameter names and just focus on the values, using parameter order as a way to map to service method arguments). If you want more control over the encoding process, you can use the following:

    pingHost ( SOAP::Data->name("Hostname")->value("www.yahoo.com")->type("string") );

Once the response object is created, you can check to see if a fault was returned:

    die "Fault: ".$response->faultcode." ".$response->faultdetail." ".$response->faultstring if $response->faultcode;

Otherwise, the result is stored in $response->result:

    print $response->result;
In the case of this example, because the PING service responds with a string, the returned value is a string.

If the response had been an array, the returned value would have been an array reference.
If the response had been a structure, the returned value would have been a hash reference.

As you can see, writing SOAP::Lite clients is very easy!

Copyright © 2001 XMethods   Comments and Suggestions are welcome. Terms of Use