private static void SendSchoolList(Socket handler, String data) { string _value = ""; using (XmlReader reader = XmlReader.Create(new StringReader(data))) { while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: Console.WriteLine(reader.Name); break; case XmlNodeType.Text: Console.WriteLine(reader.Value); _value = reader.Value; break; case XmlNodeType.XmlDeclaration: case XmlNodeType.ProcessingInstruction: Console.WriteLine(reader.Name + reader.Value); break; case XmlNodeType.Comment: Console.WriteLine(reader.Value); break; case XmlNodeType.EndElement: Console.WriteLine(reader.Name); break; } } } SchoolTB _schoolTb = new SchoolTB(); CitySchools_list _schools = _schoolTb.GetSchoolsInCity(_value); StringBuilder sb = new StringBuilder(); StringWriter stream = new StringWriter(sb); XmlSerializer x = new System.Xml.Serialization.XmlSerializer(_schools.GetType()); x.Serialize(stream, _schools); byte[] byteData = Encoding.ASCII.GetBytes(stream.ToString()); // Begin sending the data to the remote device. handler.BeginSend(byteData, 0, byteData.Length, 0, new AsyncCallback(SendCallback), handler); }
//public string GetData(string value) //{ // return string.Format("You entered: {0}", value); //} public List <string> GetSchools(string city) { SchoolTB _schoolTb = new SchoolTB(); CitySchools_list _schools = _schoolTb.GetSchoolsInCity(city); StringBuilder sb = new StringBuilder(); StringWriter stream = new StringWriter(sb); XmlSerializer x = new System.Xml.Serialization.XmlSerializer(_schools.GetType()); x.Serialize(stream, _schools); return(_schools.School_name); //return stream.ToString(); }