Zend Framework Forum

Go Back   Zend Framework Forum > Zend Framework General discussions > Resources for Developers

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-30-2009, 05:09 AM
Junior Member
 
Join Date: Mar 2009
Posts: 1
Default How to consume StrikeIron US Address Verification Web service within Zend Framework

This topic discusses how to develop a sample to consume StrikeIron web services using Zend Framework 1.7.
First, you should download the Zend Server from Download Zend Server Community Edition Beta - Zend.com download

This server provides a good way to test your sample. It has a built-in debugger that can help you saving your development time. Fortunately, the integration with StrikeIron web services within Zend Framework is easy to do, so here we go!

Step 1. Download the ZendFrameWork from Zend Community Downloads - Zend.com
Zend Framework 1.7 full is the best choice in this case. Uninstall your zip file to a folder. There is a helpful StrikeIron library in this framework, and it will be used for this sample.

Step 2. Download the Zend server, then install it.

Step 3. After your installation, copy all files in ZendFramework\library\Zend\Service\StrikeIron to Zend server\share\service\StrikeIron (you can overwrite the existing files there).

Step 4. Make sure the WSDL url in USAddressVerification.php pointing to the right version of StrikeIron US Address Verification.
Open this file in StrikeIron on Zend Server, change the WSDL value to 'http://ws.strikeiron.com/USAddressVerification5?WSDL'.
Restart the Zend server.

Step 5. Register a StrikeIron Web services account at StrikeIron US Address Verification Web Service 5.0.0 - StrikeIron to consume StrikeIron Web services. You will use the username and password received in Step 6

Step 6. Start writing the sample. Create a file called strikeiron_usaddress.php
Add the following code to the file. In this code, we use a library from StrikeIron that has already been included in Zend Framework(StrikeIron.php):
[PHP]
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Service_StrikeIron
* @subpackage Demos
* @copyright Copyright (c) 2005-2008 StrikeIron Inc. (http://www.strikeiron.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

/**
* StrikeIron US Address Verification
*/

require_once 'Zend/Service/StrikeIron.php';

if (isset($_POST) && strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
$line1 = strip_tags($_POST['line1']);
$line2 = strip_tags($_POST['line2']);
$line3 = strip_tags($_POST['line3']);

} else {
$line1 = '';
$line2 = '';
$line3 = '';

}

?>
<!DOCTYPE html public "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
</head>
<body>
<h1>Strike Iron US Address Verification Service</h1>
<form action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post">
<p>
<label>Address Line1: <input type="text" name="line1" value="<?php echo htmlspecialchars($line1, ENT_QUOTES); ?>"></label><br>
<label>Address Line2: <input type="text" name="line2" value="<?php echo htmlspecialchars($line2, ENT_QUOTES); ?>"></label><br>
<label>Address Line3: <input type="text" name="line3" value="<?php echo htmlspecialchars($line3, ENT_QUOTES); ?>"></label><br>

<input type="submit" value="Verify">
</p>
</form>
<?php
if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') {

try {
$wsClass = new Zend_Service_StrikeIron(array('username'=>'usernam e','password'=>'password'));
$client = $wsClass->getService(array('class'=>'USAddressVerification' ));
$objParam = array ('AddressLine1'=>$line1,'AddressLine2'=>$line2,'Ci tyStateZIPCode'=>$line3);

$results = (object)$client->__call('VerifyAddressUSA',array($objParam));
echo 'Call service successfully<br>';
if (isset($results))
{
//$objSInfo = new Zend_Service_StrikeIron_Decorator($results, 'SubscriptionInfo');
//$objResult = new Zend_Service_StrikeIron_Decorator($results, 'VerifyAddressUSAResult');
//echo 'Remaining hits:' . $results->RemainingHits.'<br>';
echo 'Service status:' . $results->ServiceStatus->StatusDescription.'<br>';
echo 'Address line 1 (corrected):' . $results->ServiceResult->AddressLine1.'<br>';
echo 'Address line 2 (corrected):' . $results->ServiceResult->AddressLine2.'<br>';
echo 'City :' . $results->ServiceResult->City.'<br>';
echo 'State :' . $results->ServiceResult->State.'<br>';
echo 'ZIPCode :' . $results->ServiceResult->ZIPCode.'<br>';

}

}
catch (Exception $e)
{
echo 'General error:' + $e->getMessage();
}
catch (Zend_Service_StrikeIron_Exception $e) {
echo '<p style="color: red; font-weight: bold">Error occured (' + $e->getMessage()
+ '), please try again later.</p>';
}

}

?>
<p id="poweredby" style="text-align: center; font-size: 9px;">Powered by the <a href="http://framework.zend.com">Zend Framework</a></p>
</body>
</html>

[/PHP]

Step 7. Copy this file to Zend server html root folder (Zend\Zendserver\GUI\html) then try it on web when you run the Zendserver. The url should be [zend server web root]\ZendServer\strikeiron_usaddress.php
Your sample is completed now. When the web page opens,just enter 3 lines of any US addresses into the text boxes, click Verify, then you will get interesting verified info.

Have fun!
Dan

References
1. Zend server: Zend Community Downloads - Zend.com
2. StrikeIron US Address Verification Web services 5.0: StrikeIron US Address Verification Web Service 5.0.0 - StrikeIron
Attached Files
File Type: zip strikeiron_usaddress.zip (1.8 KB, 1 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT. The time now is 07:36 PM.


Designed by: Miner Skinz Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0