CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Brendan Tompkins [MVP]

Blog First. Ask Questions Later.

Homeland Security Threat Level Service Anyone?

I've been tasked with creating a control to display the current Homeland Security Threat Level on our site's home page.  Of course, I don't want to change anything when our threat level changes, so I went in search of a Web Service that gives me this information.  I couldn't find a SOAP service, but I did find this URL provided by the Department of Homleand Security, which gives an XML string containing the current threat level.

I created this following enumeration that represents the current condition, so that I can use this information from within our .NET framework.

public enum DHSAdvisoryLevel
{
    SEVERE,
    HIGH,
    ELEVATED,
    GUARDED,
    LOW,
    UNKNOWN
}

And this static method to parse the DHSA's XML and return my enum.

public static DHSAdvisoryLevel GetHomelandSecurityThreatLevel()
{
      DHSAdvisoryLevel currentLevel = DHSAdvisoryLevel.UNKNOWN;
      try
      {
            System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
            doc.Load("http://www.dhs.gov/dhspublic/getAdvisoryCondition");
            System.Xml.XmlNodeList el = doc.GetElementsByTagName("THREAT_ADVISORY");
            string threatLevel = el[0].Attributes["CONDITION"].Value;
            currentLevel = (DHSAdvisoryLevel) Enum.Parse(typeof(DHSAdvisoryLevel), 
            threatLevel, true);
      }
      catch 
      { 
            // Do something here, if needed 
      }
      return currentLevel;
}

Now, what would be really cool is for someone to host a Web Service that returns this enum... Any takers?

-Brendan



Comments

Brendan Tompkins said:

I'd think that a web service should be more reliable than a bunch of people parsing xml and using this xml string un-typed. It's also much easier to consume a web service, than to parse xml, and hope the XML structure stays the same... If they ever change their implemenation, that one person would do the update... Really, the DHS should host the service. I dunno.. It was just a thought.
# January 30, 2004 1:33 PM

Brian Desmond said:

I'll host it. Send me a zip file with the code, binaries.
# January 30, 2004 4:52 PM

sdk said:

believe a service like this exists on
xmethods.com
# January 31, 2004 3:45 PM

Brendan Tompkins said:

sdk,

Thanks, I did find the threatLevel service at xmethods. I couln't succesfully add a web refrence to this service however... I kept getting the following error:

Custom tool error: Unable to import WebService/Schema. Unable to import binding 'threat.cfcSoapBinding' from namespace 'http://DefaultNamespace'. Unable to import operation 'threatLevel'. Types must be declared at the top level in the schema.

The service is in ColdFusion, I wonder if it's coded improperly?

-Brendan
# February 2, 2004 1:23 AM

Brendan Tompkins said:

Brian,

Thanks for the offer to host this. I ended up hosting it here at VIT.

http://www.vit.org/WebServices/HomelandSecurityService.asmx

I couldn't get the ColdFusion service to work properly. I also wanted to return the Coast Guard's MARSEC level as well.

-Brendan

# February 3, 2004 2:02 AM

grant said:

Brendan, if you still need a host for this (or any other cool service you create) let me know and we can get WeProgram.Net or another OptimizeIT server to do it.
# February 9, 2004 2:30 PM

Brendan said:

Thanks Grant! Maybe I'll take you up on it. I ended up hosting the homeland security service here, since I returned MARSEC levels too, which relates to our core business.

Thanks again!
# February 10, 2004 1:17 AM

Darrell said:

Hey Brendan,

I was playing around with this and found out that you can get the DHS images to go along with the level. You could return that as part of your web service, and people could set that up if they wanted an image.
# March 6, 2004 7:09 AM

Brendan Tompkins said:

Hey Darrell...

Yeah. You can. Do you know if these are hosted somewhere? I don't want to get in the business of hosting a bunch of GIFs..

B
# March 6, 2004 10:15 AM

Paul Watson said:

Nice one, you just provided the answer for a CPian (http://www.codeproject.com/lounge.asp?msg=806754#xx806754xx).
# April 29, 2004 8:19 AM

Brendan Tompkins said:

Nice.. Glad to help!
# April 29, 2004 8:44 AM

DEV said:

thanks Brendan for the URL
# February 1, 2005 6:31 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add

About Brendan Tompkins

Brendan has been programming with .NET since the first public beta and is owner and operator of Port Technology Services, a consultancy company providing .NET application development services to the Maritime industry. In July, 2007, he was awarded the Microsoft MVP award for ASP.NET. He's also a proud co-founder of failed .COM startup Intrinsigo, and has had a hand in the failure of numerous other businesses. He currently runs CodeBetter.Com and Devlicio.us, and lives in Norfolk, Virgina with his wife Tiara and son Ian.

View Brendan's profile on LinkedIn

Check out Devlicio.us!

Our Sponsors

Free Tech Publications