#!/usr/bin/perl -w #$file: ws_client.pl - a perl WebServices client with SOAP, call XMethods #temperature service. # use strict; use SOAP::EnvelopeMaker; use SOAP::Parser; use SOAP::Struct; use SOAP::Transport::HTTP::Client; my $zipcode = shift; $zipcode =~ /^\d+$/ or die "USAGE: $0 U.Szipcode\n"; my ($server, $port, $endpoint, $soapaction, $method, $method_urn, $message, $envelope, $response, $parser); # service address $server = 'services.xmethods.net'; $port = 80; $endpoint = '/soap/servlet/rpcrouter'; $soapaction =''; $method = 'getTemp'; # operator namespace $method_urn = 'urn:xmethods-Temperature'; # create SOAP envelope $envelope = SOAP::EnvelopeMaker->new(\$message); # set SOAP body,zipcode is the parameter name $envelope->set_body($method_urn, $method, 0,SOAP::Struct->new(zipcode=>$zipcode)); # create client call $response = SOAP::Transport::HTTP::Client->new()->send_receive($server, $port, $endpoint, $method_urn, $method,$message); # parser SOAP response message $parser = SOAP::Parser->new; $parser->parsestring($response); # get SOAP body $response = $parser->get_body; if (exists $response->{return}) { print "$zipcode Temperature: $response->{return}\n"; } else { print "A fault ($response->{faultcode}) occurred: " . "$response->{faultstring}\n"; } exit;
You are here: Home > web service > A Perl Web Service Client With SOAP
Monday, May 21, 2007
A Perl Web Service Client With SOAP
A perl WebServices client with SOAP,call XMethods temperature service.
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment