public Task <string> GetCitiesByCountry(string countryName) { var globalWeatherSoapClient = new GlobalWeatherSoapClient(); var citiesByCountryAsync = globalWeatherSoapClient.GetCitiesByCountryAsync(countryName); return(citiesByCountryAsync); }
public async Task <List <Table> > GetWeatherByCountryName(string country) { string cities = string.Empty; var soapClient = new GlobalWeatherSoapClient(globalWeatherSoap); cities = await soapClient.GetCitiesByCountryAsync(country); //string is returned in xml format return(StringConvert.ConvertXmlStringIntoObject(cities)); }
private async void button_Click(object sender, RoutedEventArgs e) { /****************************************/ /* Create the binding */ BasicHttpBinding binding = new BasicHttpBinding(); /* Set message size if required */ binding.MaxReceivedMessageSize = 20000000; /* Set the Endpoint */ EndpointAddress address = new EndpointAddress("http://www.webservicex.com/globalweather.asmx"); /****************************************/ /* Get the task */ GlobalWeatherSoapClient gwsc = new GlobalWeatherSoapClient(binding, address); /* Always a good idea to test for * Exceptions */ try { Task<string> getCities = gwsc.GetCitiesByCountryAsync(""); /************************************/ /* Place a call to another method * to do work, this event or * function while the task finishes * METHOD CALL HERE */ // Method /* This event cannot complete w/o * the await getCities task * being completed */ string citys = await getCities; /* You get the XML data & * deserialize it. * You do need to create a class * that gives you access to the XML */ XmlSerializer result = new XmlSerializer(typeof(cities.NewDataSet)); cn = (cities.NewDataSet)result.Deserialize(new StringReader(citys)); /* After deserialization, use * Lamda & Linq */ var Countries = cn.Table.Select(m => m.Country).Distinct(); /**************************************** /* Add countries to the combo box */ cmbxCountry.ItemsSource = Countries; /****************************************/ } catch (Exception) { throw; } }
public IEnumerable <string> GetCities(string countryName) { var request = new GetCitiesByCountryRequest(countryName); var citiesByCountryResult = _globalWeatherSoapClient.GetCitiesByCountryAsync(request).Result.GetCitiesByCountryResult; XmlDocument xml = new XmlDocument(); xml.LoadXml(citiesByCountryResult); XmlNodeList xnList = xml.SelectNodes("/NewDataSet/Table"); var cities = new List <string>(); foreach (XmlNode xnode in xnList) { string cityName = xnode["City"].InnerText; cities.Add(cityName); } return(cities.Distinct()); }
//user will enter country name for searching that country cities via button click private async void Button_Click_1(object sender, RoutedEventArgs e) { try { string getcity = await proxy.GetCitiesByCountryAsync(country.Text); XmlDocument xml = new XmlDocument(); xml.LoadXml(getcity); XmlNodeList elemlist = xml.GetElementsByTagName("City"); for (int i = 0; i < elemlist.Count; i++) { string city = elemlist[i].InnerText; cities.Add(city); } com_cities.DataContext = cities; } catch (Exception) { MessageDialog m = new MessageDialog("Data Not Found."); m.ShowAsync(); } }