将WSDL对象获取到SQL数据库中
本文关键字:SQL 数据库 获取 WSDL 对象 | 更新日期: 2023-09-27 18:11:30
所以我不想问这个问题,但是过去10个小时的搜索和尝试编码没有发现任何东西。
我有一个visual studio项目附带SQL数据库。我需要从谷歌天气服务API拉数据到sql表。
webservice调用是对这个站点的google api调用
以及其他几个网站,如accuweather和NOAA,来显示三者之间的差异。该项目的目标是查看数据是否相对相同,或者是否使用了不同的气象站,如果是这样,是否会在向用户报告天气的方式上造成重大差异。
我缺少的是对象的解释器可以允许我将温度,湿度等放入sql表
有没有人这样做过,并有一些建议或参考?
下面是如何使用Linq解析响应到XML
实例:http://balexandre.com/stackoverflow/7789623/
链接还包括源代码,但是使用Linq对XML进行解析是快速、简单、有趣和极其简单的:
private GoogleWheatherInfo parseGoogleWeatherResponse(string url)
{
GoogleWheatherInfo gw = new GoogleWheatherInfo();
// get the XML
XDocument doc = XDocument.Load(url);
// parse data
gw.ForecastInformation = (from x in doc.Descendants("forecast_information")
select new GWForecastInfo
{
City = x.Descendants("city").First().Attribute("data").Value,
PostalCode = x.Descendants("postal_code").First().Attribute("data").Value,
Latitude = long.Parse(string.IsNullOrEmpty(x.Descendants("latitude_e6").First().Attribute("data").Value) ? "0" : x.Descendants("latitude_e6").First().Attribute("data").Value),
Longitude = long.Parse(string.IsNullOrEmpty(x.Descendants("longitude_e6").First().Attribute("data").Value) ? "0" : x.Descendants("longitude_e6").First().Attribute("data").Value),
ForecastDate = DateTime.ParseExact(x.Descendants("forecast_date").First().Attribute("data").Value, "yyyy-MM-dd", CultureInfo.InvariantCulture),
CurrentDate = DateTime.ParseExact(x.Descendants("current_date_time").First().Attribute("data").Value, "yyyy-MM-dd HH:mm:ss K", CultureInfo.InvariantCulture),
UnitSystem = x.Descendants("unit_system").First().Attribute("data").Value
}).Single();
gw.CurrentCondition = (from x in doc.Descendants("current_conditions")
select new GWCurrentCondition
{
Condition = x.Descendants("condition").First().Attribute("data").Value,
TemperatureC = long.Parse(x.Descendants("temp_c").First().Attribute("data").Value),
TemperatureF = long.Parse(x.Descendants("temp_f").First().Attribute("data").Value),
Humidity = x.Descendants("humidity").First().Attribute("data").Value,
Image = x.Descendants("icon").First().Attribute("data").Value,
Wind = x.Descendants("wind_condition").First().Attribute("data").Value
}).Single();
gw.ForecastConditions = (from x in doc.Descendants("forecast_conditions")
select new GWForecastCondition
{
DayOfWeek = x.Descendants("day_of_week").First().Attribute("data").Value,
Low = double.Parse(x.Descendants("low").First().Attribute("data").Value),
High = double.Parse(x.Descendants("high").First().Attribute("data").Value),
Image = x.Descendants("icon").First().Attribute("data").Value,
Condition = x.Descendants("condition").First().Attribute("data").Value,
}).ToList();
return gw;
}
我希望这能让您了解解析任何XML文档是多么容易。