将WSDL对象获取到SQL数据库中 [英] Get WSDL object into a SQL Database

查看:83
本文介绍了将WSDL对象获取到SQL数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我不想问这个问题,但是最近10个小时的搜索和尝试编写代码并没有带来任何好处.

So I hate to ask this but the last 10 hours of searching and attempting to code have turned up nothing.

我有一个附有SQL数据库的Visual Studio项目.我需要将数据从Google Weather Service API提取到sql表中.

I have a visual studio project with an SQL database attached. I need to pull data from a google weather service API into the sql table.

该网站的网络服务调用是 google api调用

The webservice call is to this site google api call

以及其他几个站点,例如AccuWeather和NOAA,以显示这三个站点之间的差异.该项目的目标是查看数据是否相对相同,或者是否使用了不同的气象站,如果这样的话,会导致向用户报告天气的方式发生重大差异.

As well as a couple other sites like accuweather and NOAA to show the differences between the three. The projects goal is to see whether the data is relatively the same or if different weather stations are bring used, and if so does it cause a significant difference in the way the weather is reported to the user.

我所缺少的是该对象的解释器,它可以让我将温度,湿度等信息放入sql表中

What I'm missing is an interpreter for the object can allow me to put the temp, humidity ect into a sql table

有人做过此事并且有一些提示或参考吗?

Has anyone done this before and have some tips or references?

推荐答案

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

Here is how you can parse the response using Linq to XML

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

该链接还包括源代码,但是使用Linq到XML的解析是快速,有趣和极其简单的:

The link also include the source code, but the parsing using Linq to XML is quick easy, fun and extremely simple:

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文档有多么容易.

I hope this gives you some knowledge on how easy is to parse any XML document.

这篇关于将WSDL对象获取到SQL数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆