ZiBaT
=> Peter Levinsky
=> Programming => exercise |
PHP Pages |
Updated : 2015-11-12
|
From a PHP page consume and display a web-service.
This tool helps you to consume web services in a PHP page.
(a little bit like add service refence inVisualStudio)
I.e. 'Install' the wsdl2php tool : http://sourceforge.net/projects/wsdl2php/ (same as in Ebbe's tutorial)
download + unpack compressed file -> place the uncompressed folder somewhere reasonable - Remember location.
Find a web service to consume e.g. from the old exercise comsuming existing webservices or webservices from the schoolclass 3R
In a 'console window' run to made the stub for concurrency converter be in the folder of your wsdl2php tool (e.g. ::some-root-folder::\wsdl2php-0.2.1-pear\wsdl2php-0.2.1\bin):
php wsdl2php.php http://www.webservicex.net/CurrencyConvertor.asmx?WSDL
You need to add the path to php in your environment variable (Or use full path like: ::XAMPP-PATH::\XAMPP\php\php wsdl2php 'wsdl-file')
This will generate a PHP file (named CurrencyConvertor.php), which you have to move (or copy) to your php project, where to consume this web-service.
To use this newly created php-file you need to 'include' it in your page i.e. require_once './CurrencyConvertor.php';
Create an object (like in c#) to the stub i.e. $currencyConverter = new CurrencyConvertor;
Set up parameters to used in the web-service call e.g.
$conversionRate = new ConversionRate;
$conversionRate->FromCurrency = Currency::EUR;
$conversionRate->ToCurrency = Currency::DKK;
call the web service i.e.
$rate = $currencyConverter->ConversionRate($conversionRate);
Now $rate will hold the result of the call.
Make a page like in Ebbes tutorial to convert some amount from some currency to Danish Crowns (DKK)
Refactor the page to both have a from currency and a to currency
Try with another web service (see in exercise B) or one of your own web services
Refactor your solution to encapsulate the web-service-stub call in php-functions.