File: weather_wsdl.pl

package info (click to toggle)
libsoap-wsdl-perl 2.00.10-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 2,696 kB
  • sloc: perl: 8,422; xml: 1,769; java: 19; makefile: 15
file content (43 lines) | stat: -rw-r--r-- 1,394 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Accessing the globalweather service at
# www.webservicex.net/GlobalWeather/GlobalWeather.asmx
#
# Note that the GlobalWeather web service returns a (quoted) XML structure - 
# don't be surprised by the response's format.
#
# I have no connection to www.webservicex.net
# Use this script at your own risk.
#
# This script demonstrates the use of SOAP::WSDL in SOAP::Lite style.

use lib 'lib/';
use lib '../lib';
use File::Basename qw(dirname);
use File::Spec;
my $path = File::Spec->rel2abs( dirname __FILE__);

# SOAP::WSDL variant
use SOAP::WSDL;
my $soap = SOAP::WSDL->new();
my $som = $soap->wsdl("file:///$path/wsdl/globalweather.xml")
  ->call('GetWeather', GetWeather => 
    { CountryName => 'Germany', CityName => 'Munich' }
);

die "Error" if $som->fault();
print $som->result();

# SOAP::Lite variant:
# Note that you have to look both the proxy and the xmlns attribute 
# set on the GetWeather SOAP::Data object from the WSDL.

use SOAP::Lite +trace;
$soap = SOAP::Lite->new()->on_action( sub { join'/', @_ } )
  ->proxy("http://www.webservicex.net/globalweather.asmx");     # from WSDL
$som = $soap->call(
    SOAP::Data->name('GetWeather')
        ->attr({ xmlns => 'http://www.webserviceX.NET' }),      # from WSDL
    SOAP::Data->name('CountryName')->value('Germany'), 
    SOAP::Data->name('CityName')->value('Munich') 
);
die "Error" if $som->fault();
print $som->result();