public List <City> GetCities(string country)
        {
            if (string.IsNullOrEmpty(country))
            {
                throw new ArgumentException("Parameter country can not be null or empty.");
            }

            List <City> cities = new List <City>();

            var result = _gwsc.GetCitiesByCountry(country);

            #region Extract Cities out of API result.

            XDocument xmlDocument           = XDocument.Parse(result);
            IEnumerable <XElement> elements = xmlDocument.Elements("NewDataSet");
            foreach (var item in elements.Elements())
            {
                cities.Add(new City
                {
                    Name    = item.Element("City").Value,
                    Country = country
                });
            }
            #endregion

            return(cities);
        }
Example #2
0
            public string getWeather()
            {
                try
                {
                    address = new EndpointAddress("http://www.webservicex.net/globalweather.asmx?WSDL");

                    GlobalWeatherSoapClient gwsc = new GlobalWeatherSoapClient(binding, address);

                    string        ret_cities = gwsc.GetCitiesByCountry("Philippines");
                    List <string> city_list  = new List <string>();

                    //TODO: Read xml data into string[] of countries
                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.Load(ret_cities);
                    XmlNodeList parentNode = xmlDoc.GetElementsByTagName("NewDataSet");
                    foreach (XmlNode childrenNode in parentNode)
                    {
                        //HttpContext.Current.Response.Write(childrenNode.SelectSingleNode("//City").Value);
                        city_list.Add(childrenNode.SelectSingleNode("//City").Value);
                    }
                    // ------------------------------------------------------

                    string return_weather = string.Join(";", city_list.ToArray());
                    return(return_weather);
                }
                catch (Exception ex)
                {
                    return("Convertion Error: " + ex.Message);
                }
            }
Example #3
0
        public List <Cities> GetCityListbyCountry(string CountryName)
        {
            List <Cities> clist     = null;
            string        Countries = WService.GetCitiesByCountry(CountryName);//Add Timeout Exception

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(Countries);

            XmlNodeList list = doc.GetElementsByTagName("City");

            if (list.Count > 0)
            {
                clist = new List <Cities>();
                for (int i = 0; i <= list.Count - 1; i++)
                {
                    clist.Add(new Cities()
                    {
                        CityName = list.Item(i).InnerText
                    });
                }
            }

            return(clist);
        }
Example #4
0
        static void Main(string[] args)
        {
            var c = new GlobalWeatherSoapClient("GlobalWeatherSoap");

            Console.WriteLine(c.GetCitiesByCountry("Brazil"));

            Console.ReadKey();
        }
Example #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            GlobalWeatherSoapClient obj = new GlobalWeatherSoapClient();
            string       resultado      = obj.GetCitiesByCountry(textBox1.Text);
            DataSet      resul          = new DataSet();
            StringReader lectura        = new StringReader(resultado);

            resul.ReadXml(lectura);
            comboBox1.DataSource    = resul.Tables[0];
            comboBox1.DisplayMember = "city";
        }
Example #6
0
        public void WhenIInputCountryNameToGetCity(string p0)
        {
            GlobalWeatherSoapClient cl = new GlobalWeatherSoapClient();

            string city_ls = cl.GetCitiesByCountry(p0);

            Console.WriteLine(city_ls);
            if (!ScenarioContext.Current.ContainsKey("CityList"))
            {
                ScenarioContext.Current.Add("CityList", city_ls);
            }
        }
Example #7
0
        public IEnumerable <string> GetCitiesByCountry(string countryName)
        {
            var result = _soapClient.GetCitiesByCountry(countryName);
            var doc    = XDocument.Parse(result);
            //var idNodes = doc.SelectNodes("NewDataSet/Table/City");
            var cityList = doc.Root
                           .Elements("Table")
                           .Elements("City")
                           .Select(x => (string)x)
                           .ToList();

            return(cityList);
        }
Example #8
0
        public void handleRequest(Dictionary<string, string> data, StreamWriter OutPutStream)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<html><body><div><h1>Weather</h1>");

            GlobalWeatherSoapClient service = new GlobalWeatherSoapClient();

            sb.Append(service.GetCitiesByCountry("Austria"));

            sb.Append("</div></body></html>");
            WriteResponse(sb.ToString(), "text/html", OutPutStream);
            return;
        }
        public List <CityEntity> GetCitiesByCountry(GetCitiesByCountryArgs args)
        {
            try
            {
                List <CityEntity> citiesList = new List <CityEntity>();
                string            cities     = _weatherServiceClient.GetCitiesByCountry(args.countryName);

                return(FetchCityListFromXml(cities, args.countryName));;
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Example #10
0
        public CountryCityResult GetCities(string country)
        {
            try
            {
                using (var globalWeatherSoapClient = new GlobalWeatherSoapClient(_soapEndpointName))
                {
                    var cityXmlString = globalWeatherSoapClient.GetCitiesByCountry(country);
                    if (string.IsNullOrEmpty(cityXmlString))
                    {
                        return new CountryCityResult
                               {
                                   Exception = new InvalidDataException("Xml response is empty")
                               }
                    }
                    ;


                    var serializer = new XmlSerializer(typeof(CityResult));
                    using (var reader = new StringReader(cityXmlString))
                    {
                        var cityResponse = serializer.Deserialize(reader) as CityResult;

                        if (cityResponse == null)
                        {
                            return new CountryCityResult
                                   {
                                       Exception = new InvalidDataException("Error in deserializing xml respones")
                                   }
                        }
                        ;

                        return(new CountryCityResult
                        {
                            Status = ServiceStatus.Success,
                            Cities = cityResponse.Tables.Select(t => t.City).ToList()
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                return(new CountryCityResult
                {
                    Exception = ex
                });
            }
        }
Example #11
0
        private void HavaDurumu_Load(object sender, EventArgs e)
        {
            //Web servise bağlanabilmek için bu class'dan bir örnek aldık. constructor'ında belirttiğimiz ise endpoint ismidir. Bu endpoint ismi app.config içerisinde yer alır.

            var xml = client.GetCitiesByCountry("Turkey");
            //MessageBox.Show(xml);
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xml);

            XmlNodeList nodes = doc.GetElementsByTagName("City");

            foreach (XmlNode siradakiElement in nodes)
            {
                cmbSehirler.Items.Add(siradakiElement.InnerText);
            }
        }
Example #12
0
        public formWeather()
        {
            InitializeComponent();

            BasicHttpBinding binding = new BasicHttpBinding();

            binding.MaxReceivedMessageSize = 200000000;

            EndpointAddress address = new EndpointAddress("http://www.webservicex.com/globalweather.asmx");

            GlobalWeatherSoapClient gwsc = new GlobalWeatherSoapClient(binding, address);

            var cities = gwsc.GetCitiesByCountry("");

            XmlSerializer result = new XmlSerializer(typeof(Cities.NewDataSet));

            cn = (Cities.NewDataSet)result.Deserialize(new StringReader(cities));
        }
Example #13
0
        public formWeather()
        {
            InitializeComponent();
            binding.MaxReceivedMessageSize = 2000000;

            GlobalWeatherSoapClient gwsc = new GlobalWeatherSoapClient(binding, address);

            var cities = gwsc.GetCitiesByCountry("");

            XmlSerializer result = new XmlSerializer(typeof(Cities.NewDataSet));

            cn = (Cities.NewDataSet)result.Deserialize(new StringReader(cities));

            var Countries = cn.Table.Select(x => x.Country).Distinct();

            comboBoxCountries.Items.AddRange(Countries.ToArray());
            var Cities = cn.Table.Select(x => x.City).Distinct();

            comboBoxCities.Items.AddRange(Cities.ToArray());
        }
Example #14
0
 // GET: api/GetWeatherByCity/countryName
 public IEnumerable <string> Get(string countryName)
 {
     try
     {
         globalweatherService.GlobalWeatherSoapClient client = new GlobalWeatherSoapClient();
         //get the list of cities from the service
         var res = client.GetCitiesByCountry(countryName.Trim());
         //create the ds from the string
         var ds = getDS(res);
         if (ds == null || ds.Tables.Count == 0)
         {
             return(null);
         }
         var filePaths = ds.Tables[0]
                         .AsEnumerable()
                         .Where(p => p.Field <string>("Country").Equals(countryName, StringComparison.InvariantCultureIgnoreCase))
                         .Select(row => row.Field <string>("City"))
                         .ToArray();
         return(filePaths);
     }
     catch { return(null); }
 }
Example #15
0
 public string GetCitiesByCountry(string countryCode)
 {
     return(_client.GetCitiesByCountry(countryCode));
 }