#!/usr/bin/perl -w ##################################################### # # Client to access ExamineNames.pm through SOAP. # ####################################################### ## To see all the details of the transaction, uncomment this line. #use SOAP::Lite +trace => 'all', on_fault => \&faultHandler; use SOAP::Lite on_fault => \&faultHandler; ## Define uri and proxy. my $uriNamespace = 'ExamineNames'; my $proxyEndpoint = 'http://bob.marlboro.edu/~msie/2002/ipl/perl/lectures/jun15/names/server-ExamineNames.cgi'; ## Get name from the console. my $defaultNick = "Jim"; print " Type in a first name [$defaultNick] : "; chomp(my $nickname = <>); $nickname = $nickname || $defaultNick; ## Create a SOAP::Lite object, and aim it ## at the proxyEndpoint and uriNamespace. ## (I find this notation confusing. ## Note that the "proxy" is the actual server url, ## while the "uri" is simply a namespace designation.) ## The SOAP::Lite server treats the uri as ## the name of perl module containing the remote methods. ## Other servers may use their own conventions. my $soap = SOAP::Lite ->uri($uriNamespace) ->proxy($proxyEndpoint); ## Invoke a remote call to the "getGender" method. ## This returns a SOAP::SOM object, which holds the ## value(s) returned and pretty much everything else in the XML response. my $som = $soap->getGender($nickname); ## If the service you're calling expects a specific form ## for the input parameter(s), you can wrap a parameter in ## a SOAP::Data object. ## Here's how you could specify the name, type, and value of a parameter. ## The one below would turn into Jim #my $data = SOAP::Data # ->name('nickname') # ->type('string') # ->value($nickname); #my $som = $soap->getGender($data); ## ## There are other options and forms allowed as well, for example # $data = SOAP::Data->name( height=>3)->encodingStyle('http://xml...'); print " The gender of '$nickname' is ", $som->result, ".\n"; ## And some similar calls to the other two services in this ExamineNames class. my $fullname = $soap->expandNickname($nickname)->result; print " The fullname of '$nickname' is '$fullname'. \n"; my $name1 = "Jim Mahoney"; my $name2 = "JAMES H MAHONEY"; my $rating = $soap->sameNames($name1, $name2)->result; print " Rating of '$name1' == '$name2' is '$rating'. \n"; exit; # -------------------------------------------------- sub faultHandler { my ($soap, $som) = @_; # see distribution/SOAP-Lite-0.55/examples/ if ($som and $som->fault) { my $faultstring = $som->faultstring; my $faultdetail = $som->faultdetail; print "OOPS: " . $som->faultcode . "\n"; print " " . $faultstring if $faultstring; print " " . $faultdetail if $faultdetail; } print " soap transport status : '" . $soap->transport->status . "'\n"; die " SOAP fault"; }