Utilizing Webservices
A few weeks ago, I was asked to translate a script that I wrote in ASP a year ago to Perl, which I did, because the client wanted the project to be written in Perl.
Well, can’t blame the client since ASP is kind of outdated anyway.
Later on, I was thinking to myself that it won’t be very fun for me to rewrite the script again everytime a client wants the server script to be in a different language that I don’t yet have.
So I decided to write a Web Service for that particular script. I think that it is a very useful tool and would love to encourage other people to start utilizing it or at least get familiar with it.
Web Service, just like its name implies is a “service”. The major advantage is that different platforms and programming languages can use the “service”.
Since this post is targeted to encourage people to take a look at Web Service, I am only going to give a preview of things that can be done using Web Service.
This Flash movie utilize the Web Service that I wrote here to get the distance between 2 US zipcodes
If you have SOAP package for PEAR and some other prerequisite packages like Mail_Mime, Net_URL, HTTP_Request, and Net_DIME installed, you can also use the following PHP script to utilize the Web Service previewed in the Flash movie above.
<?php
require('SOAP/Client.php');
$soap = new SOAP_WSDL('http://capcai.indorelation.com/webservices/ZipWS.php?wsdl');
$proxy = $soap->getProxy();
$proxy->setOpt("timeout",0);
$hasil = $proxy->getDistance("78741", "90010", "mi");
print_r ($hasil);
?>
Surprised? It takes only 6 lines of code to access and display the output.
If you are interested in learning more about Web Service, Alessandro Crugnola of sephiroth.it has written a very nice tutorial here.