#!/usr/bin/perl -w ########################################## # A demo SOAP client ########################################## ## Set the callback fault handler subroutine. ## To see HTTP headers and SOAP envelopes, append " , +trace=>'debug'; " use SOAP::Lite on_fault => \&faultHandler; ## This SOAP service is described at ## http://www.shinkatech.com/interop/NSLookup/Main.phtml. ## We could use the remote WSDL to define this service. #my $wsdl = "http://www.shinkatech.com/interop/NSLookup/NSLookup.wsdl"; ## But since I've already coped its WSDL definition here, I just use it. my $wsdl = "file:./NSLookup.wsdl"; ## Define the SOAP service from the WSDL. ## Create a corresponding perl object that can invoke the remote SOAP calls. my $dnsLookup = SOAP::Lite->service($wsdl); my $name = "bob.marlboro.edu"; print "Calling dns lookup on '$name'...\n"; ## Call the remote server's SOAP object methods. ## As with any objects, these have methods with specific inputs and outputs. ## They are all defined within the WSDL, in the form ## ## ## input-arguments ## return-values ## ## ## Here translate() takes a single string which is a name or IP address. my $answerHash = $dnsLookup->translate($name); # This is a remote call. ## Typically if there's more than one return value ## then SOAP::Lite will wrap them up into a hash. print "Done. Result is \n"; foreach my $key (sort keys %$answerHash) { print " $key = " . $answerHash->{$key} . "\n"; } exit; ##-- This gets called if there's a problem. ------------------------- sub faultHandler { my ($soap, $som) = @_; # see distribution/SOAP-Lite-0.55/examples/ die( $som->fault ? $som->faultstring : $soap->transport->status ); }