Free Weather Forecast Web Service

The National Weather Service has a Web service you can use:

http://www.weather.gov/xml/

To use it:

1. Copy the WSDL:

http://www.weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl

2. Right-click on the Web site and select Add Web Reference.

3. Paste the WSDL address, from step #1 above into the address bar and click Go.

4. After you see the response from the Web service, which is a description of the service, click the Add Reference button, which will add gov.weather.www to the Web References folder.

5. The following service shows one way to use the service:

        protected void Page_Load(object sender, EventArgs e)
        {
            var weather = new gov.weather.www.ndfdXML();
            var result = weather.LatLonListZipCode("80130");
            var denWeather =
                weather.GmlTimeSeries(
                    "39.5432,-104.939",
                    DateTime.Parse("12/31/09"),
                    DateTime.Parse("01/02/10"),
                    WebTest.gov.weather.www.compTypeType.Between,
                    WebTest.gov.weather.www.featureTypeType.Forecast_Gml2AllWx,
                    "maxt,mint,wx");
            Response.Write(denWeather);
        }

I called LatLonListZipCode to get the LatLon for the specified Zip Code.  Then I passed that LatLon to the first parameter of the call to GmlTimeSeries.  Yep, I cheated by hitting a break point and copying the latlon out of the XML document in result.  denWeather is another XML document that is returned by the service.  You can use LINQ to XML to get the return values and display them on the screen however you want.  You should visit http://www.weather.gov/xml/ for a full description of what methods are available, the meaning of their parameters, and any other information about the API.

Published by Joe Mayo

Author and independent software consultant. Specializing in Microsoft .NET technology. #ai #botframework #chatbots

3 thoughts on “Free Weather Forecast Web Service

  1. I don’t understand the instruction, right-click on the Web site and select Add Web Reference. When I navigate to the site and right-click on the site, there is no Add Web Reference command.

  2. When I originally commented I clicked the “Notify me when new comments are added” checkbox
    and now each time a comment is added I get four emails with the same comment.
    Is there any way you can remove me from that service?
    Thank you!

Leave a comment