I have been getting weather information from the National Weather service by accessing their XML files. But as of today I keep getting an access denied error (403) Has my server been block? if so What can I use to get weather info for free in the United States ?
I can't believe my web service was block with just a couple of hits. Just in case this is the schedule job I was using to test the weather data:
public override async Task ExecuteAsync()
{
GoogleGeocoder geocoder;
//Geocode variables
string apiKey = WebConfigurationManager.AppSettings["googleApiKey"];
if (String.IsNullOrEmpty(apiKey))
{
geocoder = new GoogleGeocoder();
}
else
{
geocoder = new GoogleGeocoder(apiKey);
}
string longitude = string.Empty;
string latitude = string.Empty;
var xdoc = new XDocument();
var project = Project();
//Query for each project and get their longitude and latitude
DataTable dataTable = SqlHelper.ExecuteDataset("getAll", "1").Tables[0];
if (dataTable.Rows.Count > 0) {
foreach (DataRow dataRow in dataTable.Rows) {
Map.DataToObject(dataRow, project);
//Find Longitude and latitude based on zipcode or address.
IEnumerable<Address> addresses = geocoder.Geocode(project.SiteCity + "," + project.SiteState + " " + project.SitePostalCode);
longitude = addresses.First().Coordinates.Latitude.ToString();
latitude = addresses.First().Coordinates.Longitude.ToString();
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://forecast.weather.gov/MapClick.php");
string uri = "http://forecast.weather.gov/MapClick.php?lat=" + latitude + "&lon=" + longitude + "&FcstType=dwml";
HttpResponseMessage response = await client.GetAsync(uri);
xdoc = XDocument.Parse(await response.Content.ReadAsStringAsync(), LoadOptions.None);
Services.Log.Info(xdoc.Descendants("wordedForecast").Descendants("text").ElementAt(0).Value);
//Update or create an weather entry for each project
}
}
return;//Task.FromResult(true);
}
}