c# - Get specific values from XML returned by web service -


guessing basic stuff, can't figure out. i'm using web service returns xml show below, i've far dealt web methods return single string/int etc. don't know how deal being returned. cdyne weather web service, , there no in depth examples noob me.

 <?xml version="1.0" encoding="utf-8"?> -<forecastreturn xmlns="http://ws.cdyne.com/weatherws/" xmlns:xsd="http://www.w3.org/2001/xmlschema" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance">     <success>true</success>     <responsetext>city found</responsetext>     <state>ny</state>     <city>new york</city>     <weatherstationcity>white plains</weatherstationcity>     -<forecastresult>         -<forecast>             <date>2014-09-20t00:00:00</date>             <weatherid>2</weatherid>             <desciption>partly cloudy</desciption>             -<temperatures>                 <morninglow>52</morninglow>             <daytimehigh>73</daytimehigh>             </temperatures>             -<probabilityofprecipiation>                 <nighttime>00</nighttime>                 <daytime>10</daytime>             </probabilityofprecipiation>         </forecast>         -<forecast>             <date>2014-09-21t00:00:00</date>             <weatherid>3</weatherid>             <desciption>mostly cloudy</desciption>             -<temperatures>                 <morninglow>63</morninglow>                 <daytimehigh>78</daytimehigh>             </temperatures>             -<probabilityofprecipiation>                 <nighttime>10</nighttime>                 <daytime>20</daytime>             </probabilityofprecipiation>         </forecast>     </forecastresult> </forecastreturn> 

right i'm in need of description first forecast stick in label.

    weatherwebservice.weather weatherservice = new weatherwebservice.weather();      private void btngo_click(object sender, eventargs e)     {         weatherservice.getcityforecastbyzip(txtzip.text);          lbldescription.text = magicvariablex;     } 

the service has been added fine , can called, don't have clue whats being returned, when single variable string.int being sent when tested in browser displayed xml, not treated such in code.

before go down path of trying parse xml... you're looking description of first forecast returned, correct?

the method .getcityforecastbyzip returns type of "forecastreturn" opposed "int" or "string" types. common scenario.

i had success moment ago:

        forecastreturn fr = new forecastreturn();         weather service = new weather();         fr = service.getcityforecastbyzip("44060");         string yourmagicvariable = fr.forecastresult[0].desciption; 

note: description misspelled. typo on cdyne side of how defined type forecastreturn.

additionally, because .asmx service. make sure reference service old .net 2.0 service in "advanced"


Popular posts from this blog