Andrew Trice
Real-World Rich Internet Applications
Tuesday January 23, 2007
Census Mashups Using StrikeIron Web Services and Yahoo Maps in Flex 2
Not too long ago, StrikeIron was in our office demonstrating some of the services that they provide... If you weren't aware, StrikeIron is a provider and distributor of web services. They have a ton of services that you can purchase for various tasks, and they can also resell services that you have developed. One of their free services is the "Super Data Pack"; a free set of web services (free up to 10,000 hits per month) that encompass a broad range of functionality, and are great for creating mashups or extending the functionality of your applications AND they have a crossdomain.xml file, so it works with Flex!
I thought it would be a good idea to take some of their services and put them to use within a Flex application, and here's what I came up with...
![[image]](http://mowser.com/img?url=http%3A%2F%2Fwww.cynergysystems.com%2Fblogs%2Fblogs%2Fandrew.trice%2Fstrikeiron%2Fscreenshot.jpg)
Launch Census Dashboard Mashup
It is a mashup using StrikeIron's Zip Code Information Web Service, StrikeIron's Population Demographics By ZIP Code Web Service and Yahoo Maps to give detailed information for a specific US zip code. I find it to actually be a really cool tool. You can drill into the data to see regional age distribution, renter/owner distribution, and ethnic diversity, among other population/housing demographics. All of the data is based on United States Census information. I wish it showed income distribution for the specified areas, but the free web services do not contain that information. This tool could be an especially handy research tool if you are in the market for a new home. I have noticed that some zip codes don't return any demographic data (which I assume is not in the Census data), but for the most part it is very accurate.
When putting this together, I started with a basic application that called just one service... You can check it out here. In order to use StrikeIron's services, you need to include your login information in the SOAP header. This isn't difficult, but was a little tricky at first. In order to access the services, you have to create a soap header and attach it to the web service instance. Here's what I did:
Web Service Instantiation:
<mx:WebService id="ws"
wsdl="http://sdpws.strikeiron.com/sdpCensus?WSDL"
useProxy="false">
<mx:operation name="GetCensusInfoForZipCode"
result="onResult( event );"
fault="onFault( event )" />
</mx:WebService>
Soap Header Modification:
private function onCreationComplete() : void
{
//add the LicenseInfo parameters to the web service SOAP header
var qName : QName = new QName( "http://ws.strikeiron.com", "LicenseInfo" );
var licenseInfo : XML = <LicenseInfo>
<RegisteredUser>
<UserID>userid</UserID>
<Password>password</Password>
</RegisteredUser>
</LicenseInfo>;
var header : SOAPHeader = new SOAPHeader( qName, licenseInfo );
ws.addHeader( header );
sendData();
}
One thing to watch out for... When you try to log in with invalid credentials, you will not get a HTTP 400 error code. You will get a 403: Forbidden code. When that happens, you cannot see any error messages from the server through the Flex environment. You get an error message in Flex stating "Error in socket". In order to accurately debug and figure out what was going on, I had to use Ethereal (a protocol analyzer) to intercept the http traffic and see the error messages.


