The following information will assist you in configuring your development environment to connect with and use the HIW's SOAP Service.
Refer to the appropriate code below for your chosen development language.
using System; using NCHS.HIW.Samples.CSharp.SOAP.HIWService; namespace NCHS.HIW.Samples.CSharp.SOAP { public class Program { /// <summary>The entry point of the application.</summary> static void Main() { if (ShowSearch()) ShowIndicatorInfo(); Console.WriteLine(); Console.WriteLine("Done."); Console.ReadKey(); } private static bool ShowSearch() { string searchTerms = null; //Get input from the user. while (string.IsNullOrEmpty(searchTerms)) { Console.Clear(); Console.Write("What would you like to search for?: "); searchTerms = Console.ReadLine(); } Console.Clear(); Console.WriteLine("Searching..."); //Create a SOAPClient using the configuration from the App.config file. using (SOAPClient client = new SOAPClient()) { //Perform a search by keyword. IndicatorDescription[] results = client.SearchIndicatorDescriptions(searchTerms.Split(' '), 1); Console.Clear(); if (results == null || results.Length == 0) Console.WriteLine("Your search for \"{0}\" did not return any results.", searchTerms); else { //Write the information to the console. Console.WriteLine("Your search for \"{0}\" returned {1} result(s).", searchTerms, results.Length); foreach (IndicatorDescription result in results) Console.WriteLine("\tID: {0}\t{1}", result.ID, result.ShortDescription); return true; } } return false; } private static void ShowIndicatorInfo() { string idString = null; int id; //Ask for an indicator ID, loop until a valid number is entered. do { Console.WriteLine(); Console.Write("Please enter the ID of the Indicator Description you would like to view.: "); idString = Console.ReadLine(); } while (!int.TryParse(idString, out id)); Console.Clear(); Console.WriteLine("Loading..."); //Create a SOAPClient using the configuration from the App.config file. using (SOAPClient client = new SOAPClient()) { //Attempt to get the requested IndicatorDescription. IndicatorDescription indicatorDescription = client.GetIndicatorDescriptionByID(id); Console.Clear(); //Write the information to the console. if (indicatorDescription == null) Console.WriteLine("Could not locate Indicator Description with ID of \"{0}\".", id); else { Console.WriteLine(indicatorDescription.ShortDescription); Console.WriteLine(indicatorDescription.FullDescription); Console.WriteLine("\tSupplier: {0}", indicatorDescription.DataSupplier); Console.WriteLine("\tDimensions: {0}", indicatorDescription.AvailableDimensions); Console.WriteLine("\tGeo. levels: {0}", indicatorDescription.GeographicLevels); Console.WriteLine("\tNumerator: {0}", indicatorDescription.NumeratorDescription); Console.WriteLine("\tDenominator: {0}", indicatorDescription.DenominatorDescription); Console.WriteLine("\tUnits: {0}", indicatorDescription.ValueLabel); } } } } }
Imports NCHS.HIW.Samples.VisualBasic.SOAP.HIWService Namespace NCHS.HIW.Samples.VisualBasic.SOAP Module Program ''' <summary>The entry point of the application.</summary> Sub Main() If ShowSearch() Then ShowIndicatorInfo() End If Console.WriteLine() Console.WriteLine("Done.") Console.ReadKey() End Sub Private Function ShowSearch() As Boolean Dim searchTerms As String = Nothing 'Get input from the user. While (String.IsNullOrEmpty(searchTerms)) Console.Clear() Console.Write("What would you like to search for?: ") searchTerms = Console.ReadLine() End While Console.Clear() Console.WriteLine("Searching...") 'Create a SOAPClient using the configuration from the App.config file. Using client As New SOAPClient() 'Perform a search by keyword. Dim results As IndicatorDescription() = client.SearchIndicatorDescriptions(searchTerms.Split(" "), 1) Console.Clear() If (results Is Nothing OrElse results.Length = 0) Then Console.WriteLine(String.Format("Your search for ""{0}"" did not return any results.", searchTerms)) Else 'Write the information to the console. Console.WriteLine(String.Format("Your search for ""{0}"" returned {1} result(s).", searchTerms, results.Length)) For Each result In results Console.WriteLine(String.Format("{0}ID: {1}{0}{2}", vbTab, result.ID, result.ShortDescription)) Next Return True End If End Using Return False End Function Private Sub ShowIndicatorInfo() Dim idString As String = Nothing Dim id As Integer Do Console.WriteLine() Console.Write("Please enter the ID of the Indicator Description you would like to view.: ") idString = Console.ReadLine() Loop While Not Integer.TryParse(idString, id) Console.Clear() Console.WriteLine("Loading...") 'Create a SOAPClient using the configuration from the App.config file. Using client As New SOAPClient() 'Attempt to get the requested IndicatorDescription. Dim indicatorDescription As IndicatorDescription = client.GetIndicatorDescriptionByID(id) Console.Clear() 'Write the information to the console. If indicatorDescription Is Nothing Then Console.WriteLine(String.Format("Could not locate Indicator Description with ID of ""{0}"".", id)) Else Console.WriteLine(indicatorDescription.ShortDescription) Console.WriteLine(indicatorDescription.FullDescription) Console.WriteLine(String.Format("{0}Supplier: {1}", vbTab, indicatorDescription.DataSupplier)) Console.WriteLine(String.Format("{0}Dimensions: {1}", vbTab, indicatorDescription.AvailableDimensions)) Console.WriteLine(String.Format("{0}Geo. levels: {1}", vbTab, indicatorDescription.GeographicLevels)) Console.WriteLine(String.Format("{0}Numerator: {1}", vbTab, indicatorDescription.NumeratorDescription)) Console.WriteLine(String.Format("{0}Denominator: {1}", vbTab, indicatorDescription.DenominatorDescription)) Console.WriteLine(String.Format("{0}Units: {1}", vbTab, indicatorDescription.ValueLabel)) End If End Using End Sub End Module End Namespace
<!DOCTYPE html /> <html> <head> <title>JavaScript SOAP Example</title> <script src="Content/JavaScripts/jquery-1.7.1.min.js"></script> <style type="text/css"> #searchResultsContainer, #indicatorContainer { display: none; } #searchResultsList strong, #indicatorContainer strong { display: inline-block; width: 150px; } </style> </head> <body> <h1>What would you like to search for?</h1> <input id="searchText" type="text" /> <button id="searchButton" onclick="search();">Search</button> <div id="searchResultsContainer"> <h2 id="searchResultsHeader"></h2> <ul id="searchResultsList" /> </div> <div id="indicatorContainer"> <h2 id="indicatorHeader"></h2> <p id="indicatorDescription"></p> <ul id="indicatorDetails"> <li><strong>Supplier:</strong> <span id="indicatorSupplier"></span></li> <li><strong>Dimensions:</strong> <span id="indicatorDimensions"></span></li> <li><strong>Geographic levels:</strong> <span id="indicatorGeographicLevels"></span></li> <li><strong>Numerator:</strong> <span id="indicatorNumerator"></span></li> <li><strong>Denominator:</strong> <span id="indicatorDenominator"></span></li> <li><strong>Units:</strong> <span id="indicatorUnits"></span></li> </ul> </div> <script type="text/javascript"> //Set the baseUrl to the location of the REST service. var baseUrl = "http://services.healthindicators.gov/v2/REST.svc/"; //Performs a search using the provided text. // Calls: IndicatorDescriptions/[keywords]/Search/[page] // See: http://www.healthindicators.gov/Developers/ServiceMethods#Search-IndicatorDescriptions function search() { //Get the search text from the search textbox. var searchText = $("#searchText").val(); //Use the jQuery library to make an AJAX call to the service. $.ajax( { url: baseUrl + "IndicatorDescriptions/" + searchText + "/Search/1", type: "GET", dataType: "json", success: searchCallback, accept: "application/json" }); } //This function is called by the AJAX call which is created in the search function when the call has completed successfully. function searchCallback(data) { var resultCount = data.length; if (resultCount == 0) $("#searchResultsHeader").text("Your search for \"" + $("#searchText").val() + "\" did not return any results."); else { var searchResultsList = $("#searchResultsList"); $("#searchResultsHeader").text("Your search for \"" + $("#searchText").val() + "\" returned " + resultCount + " result(s)."); searchResultsList.empty(); //Add each result to the list. $(data).each(function () { searchResultsList.append($("<li><strong>ID: <a href=\"#\" onclick=\"getDetails($(this).text())\">" + this.ID + "</a></strong> " + this.ShortDescription + "</li>")); }); } //Show the results container. $("#searchResultsContainer").show(); } //Gets information for the Indicator Description which matches the provided ID. // Calls: IndicatorDescription/[id] // See: http://www.healthindicators.gov/Developers/ServiceMethods#IndicatorDescription function getDetails(id) { //Use the jQuery library to make an AJAX call to the service. $.ajax( { url: baseUrl + "IndicatorDescription/" + id, type: "GET", dataType: "json", success: getDetailsCallback, accept: "application/json" }); } //This function is called by the AJAX call which is created in the getDetails function when the call has completed successfully. function getDetailsCallback(data) { //Update the displayed information. if (data == null) { $("#indicatorHeader").text("Could not locate the indicator description."); $("#indicatorDetails").hide(); } else { $("#indicatorHeader").text(data.ShortDescription); $("#indicatorDescription").text(data.FullDescription); $("#indicatorSupplier").text(data.DataSupplier); $("#indicatorDimensions").text(data.AvailableDimensions); $("#indicatorGeographicLevels").text(data.GeographicLevels); $("#indicatorNumerator").text(data.NumeratorDescription); $("#indicatorDenominator").text(data.DenominatorDescription); $("#indicatorUnits").text(data.ValueLabel); $("#indicatorContainer").show(); $("#indicatorDetails").show(); } } </script> </body> </html>
This example details how to construct a SearchGroup and SearchParameters for use in the filter service methods. Using JSON and XML is only necessary if you are using the REST API. Using the SOAP API you can programmatically create your query in an object-oriented way. You must adhere to the following rules when using the filter methods via the REST API:
Content-Type
application/json
application/xml
Accepts
Element
__type
SearchParameter:#S3.Common.Search
For more information regarding how to use the filter API methods, please utilize the following resources:
The queries shown below are meant to be used with the FilterIndicators API Method. Use the REST Tester to build and test your own queries. The first example is a simple query which filters Obesity data within Ohio. The second example is a more complex query which filters Obesity data with a value greater than or equal to 25% in either 2007 or 2008.
{ "Mode":"And", "Elements": [ { "__type":"SearchParameter:#S3.Common.Search", "Name":"IndicatorDescriptionID", "Operator":"Equal", "Value":"15" }, { "__type":"SearchParameter:#S3.Common.Search", "Name":"LocaleID", "Operator":"Equal", "Value":"39" } ], "Page":1 }
{ "Mode":"And", "Elements": [ { "__type":"SearchParameter:#S3.Common.Search", "Name":"IndicatorDescriptionID", "Operator":"Equal", "Value":"15" }, { "__type":"SearchParameter:#S3.Common.Search", "Name":"FloatValue", "Operator":"GreaterThanOrEqual", "Value":"25" }, { "__type":"SearchGroup:#S3.Common.Search", "Mode":"Or", "Elements": [ { "__type":"SearchParameter:#S3.Common.Search", "Name":"TimeframeID", "Operator":"Equal", "Value":"2007" }, { "__type":"SearchParameter:#S3.Common.Search", "Name":"TimeframeID", "Operator":"Equal", "Value":"2008" } ] } ] , "Page":1 }
<SearchQuery xmlns="http://schemas.datacontract.org/2004/07/S3.Common.Search" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> <Mode>And</Mode> <Elements> <SearchElement i:type="SearchParameter"> <Name>IndicatorDescriptionID</Name> <Operator>Equal</Operator> <Value>15</Value> </SearchElement> <SearchElement i:type="SearchParameter"> <Name>LocaleID</Name> <Operator>Equal</Operator> <Value>39</Value> </SearchElement> </Elements> <Page>1</Page> </SearchQuery>
<SearchQuery xmlns="http://schemas.datacontract.org/2004/07/S3.Common.Search" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> <Mode>And</Mode> <Elements> <SearchElement i:type="SearchParameter"> <Name>IndicatorDescriptionID</Name> <Operator>Equal</Operator> <Value>15</Value> </SearchElement> <SearchElement i:type="SearchParameter"> <Name>FloatValue</Name> <Operator>GreaterThanOrEqual</Operator> <Value>25</Value> </SearchElement> <SearchElement i:type="SearchGroup"> <Mode>Or</Mode> <Elements> <SearchElement i:type="SearchParameter"> <Name>TimeframeID</Name> <Operator>Equal</Operator> <Value>2007</Value> </SearchElement> <SearchElement i:type="SearchParameter"> <Name>TimeframeID</Name> <Operator>Equal</Operator> <Value>2008</Value> </SearchElement> </Elements> </SearchElement> </Elements> <Page>1</Page> </SearchQuery>
Developed by the National Center for Health Statistics 3311 Toledo Road Hyattsville, MD 20782 (800) 232-4636 Send comments or questions to HealthIndicators@cdc.gov.