10.07.2015 Views

Beginning Web Development With Perl : From Novice to ... - Nabo

Beginning Web Development With Perl : From Novice to ... - Nabo

Beginning Web Development With Perl : From Novice to ... - Nabo

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

150CHAPTER 7 ■ SOAP-BASED WEB SERVICESThe method that I’m using for this example is NDFDgenByDay(), which accepts five parametersas arguments, for the latitude, longitude, start date, number of days, and format. Of course,this code assumes that the values are all set in the variables for latitude, longitude, and so on.So, here they are (using the latitude and longitude for Stevens Point, Wisconsin):my $latitude = "44.52";my $longitude = "-89.58";my $startdate = "2005-04-28";my $numdays = "5";my $format = "12 hourly";The service does not require that the parameters be sent as a specific type. In other words,SOAP::Lite’s guesses, though incorrect in this case, work okay with this SOAP service. To set upthe method call for this service, use the SOAP::Data->name() method <strong>to</strong> set the name of eachparameter along with its corresponding value:->NDFDgenByDay(SOAP::Data->name("latitude" => $latitude),SOAP::Data->name("longitude" => $longitude),SOAP::Data->name("startDate" => $startdate),SOAP::Data->name("numDays" => $numdays),SOAP::Data->name("format" => $format));<strong>With</strong> the method call set up correctly, you merely need <strong>to</strong> print the result:print $soap->result;■Tip You can use the National Weather Service’s site <strong>to</strong> find the latitude and longitude for your location.This service is available only in the United States. Also note that this service may have changed by the timeyou’re reading this. Visit http://weather.gov/xml/ for the most current information. There, you’ll findmore information about the National Weather Service’s XML initiative, including SOAP information.Listing 7-7 (Callnws.pl) shows the complete code for calling the National Weather ServiceSOAP service.Listing 7-7. Calling the National Weather Service SOAP Service#!/usr/bin/perl -wuse SOAP::Lite;use strict;#Be sure <strong>to</strong> change these unless you live in Stevens Point# and want an old forecast (since it doesn't work with past dates)my $latitude = "44.52";my $longitude = "-89.58";my $startdate = "2005-04-28";

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!