2011-10-17 4 views
-2

그래서이 질문을하기는 싫지만 검색 및 코드 작성을 시도한 지난 10 시간 동안 아무것도 표시되지 않았습니다.WSDL 객체를 SQL 데이터베이스로 가져 오기

SQL 데이터베이스가 연결된 시각적 스튜디오 프로젝트가 있습니다. Google 날씨 서비스 API에서 SQL 테이블로 데이터를 가져와야합니다.

웹 서비스 호출이 사이트 google api call

뿐만 아니라 세 사이의 차이를 보여 AccuWeather의와 NOAA 같은 몇 가지 다른 사이트입니다. 프로젝트 목표는 데이터가 상대적으로 동일하거나 다른 기상 관측소가 사용되는지 여부를 확인하는 것입니다. 그렇다면 날씨가 사용자에게보고되는 방식에 중요한 차이를 일으 킵니다.

내가 개체에 대한 통역이 날은 습도 요법

사람이 전에 이런 짓을 한 SQL 테이블에 임시을 넣고 몇 가지 조언 참조를 가질 수 있도록 할 수있다 누락? 여기

+0

현재 직면 한 문제는 무엇입니까? – V4Vendetta

+0

현재 웹 서비스에서 객체를 가져 왔지만 객체를 구문 분석 할 수 없습니다. – wyo9089

+2

질문이 명확하지 않습니다. 어떤 Google 날씨 서비스를 사용하고 있는지 알려주는 자세한 정보를 제공하십시오. – gprasant

답변

1

는 XML에

라이브 예를 Linq에를 사용하여 응답을 구문 분석 할 수있는 방법입니다 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 문서를 구문 분석하는 것이 얼마나 쉬운에 대한 몇 가지 지식을 제공하겠습니다.

관련 문제