home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Perl CookbookPerl CookbookSearch this book

18.14. Writing a SOAP Client

18.14.2. Solution

Use the SOAP::Lite module from the SOAP-Lite distribution:

use SOAP::Lite;

$server = SOAP::Lite
       -> uri("http://localhost/Namespace")
       -> proxy("http://server.example.com/path");
$result = $server->call('ClassName.handler', @ARGS);
die $call->faultstring if $call->fault;
print $call->result;

18.14.3. Discussion

A single SOAP server may offer remote access to the methods of many classes. A client identifies the class upon which it wishes to invoke methods with the uri parameter. The hostname in the argument is irrelevant; only the path portion (the class name) matters. For example, these two URIs are equivalent:

http://modacrylic.clue.com/GimpyMod
http://weenies.mit.edu/GimpyMod

As with XML-RPC, the proxy argument is the server's URL. For example, if your SOAP server is implemented as a CGI script, the proxy call looks like this:

$server->proxy("http://server.example.com/path/to/server.cgi");

Invoke remote methods as you do with XML-RPC, either with the call method:

$returned = $server
         -> call("getRecordByNumber", 12, { format => "CSV" })
         -> result;

or by invoking the method on a SOAP::Lite object directly:

$returned = $server
         -> getRecordByNumber(12, { format => "CSV" })
         -> result;

or using autodispatch:

use SOAP::Lite +autodispatch =>
  uri   => "http://identifier.example.com/Namespace",
  proxy => "http://server.example.com/path";

$returned = getRecordByNumber(12, { format => "CSV" });

You can also use this with OO syntax:

$returned = Some::Remote::Module->getRecordByNumber(12, { format => "CSV" });


Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.