将WSDL对象获取到SQL数据库中

所以我讨厌问这个,但是最后10个小时的搜索和尝试编码都没有发现。

我有一个Visual Studio项目,附带一个SQL数据库。 我需要将谷歌天气服务API中的数据提取到sql表中。

网络服务电话是这个网站谷歌API呼叫

以及像accuweather和NOAA这样的其他几个网站,以显示三者之间的差异。 项目目标是查看数据是否相对相同,或者是否使用了不同的气象站,如果是这样,则会导致向用户报告天气的方式存在显着差异。

我缺少的是对象的解释器可以允许我将临时,湿度等放入sql表中

有没有人以前做过这个并有一些提示或参考?

以下是使用Linq to XML解析响应的方法

实例: http : //balexandre.com/stackoverflow/7789623/

该链接还包括源代码,但使用Linq to 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文档是多么容易。