using System; using System.Linq; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; using System.Xml.Linq; using System.Data; using System.Data.Odbc; using System.Collections; using System.Xml.Serialization; using System.ServiceModel.Configuration; [System.Web.Services.WebService( Namespace = "http://microsoft.com/webservices/", Description = "Crud operations on the Entity Centre in the Courier database")] public class Service : System.Web.Services.WebService { public Service() { //Uncomment the following line if using designed components //InitializeComponent(); } [WebMethod] //[XmlElement(Type = typeof(Centre))] [XmlInclude(typeof(Centre))] public Centre [] getCentres() { string MyConString = "DRIVER={MySQL ODBC 3.51 Driver};" + "SERVER=localhost;" + "DATABASE=Courier;" + "UID=root;" + "PASSWORD=password;" + "OPTION=3"; ArrayList returnedList= new ArrayList(); OdbcConnection DbConnection = new OdbcConnection(MyConString); DbConnection.Open(); OdbcCommand DbCommand = DbConnection.CreateCommand(); DbCommand.CommandText = "SELECT * FROM CENTRE"; OdbcDataReader DbReader = DbCommand.ExecuteReader(); string retString ="usual"; int fCount = DbReader.FieldCount; for (int i = 0; i < fCount; i++) { retString = DbReader.GetName(i); } while (DbReader.Read()) { Centre temp= new Centre(); for (int i = 0; i < fCount; i++) { retString = DbReader.GetString(i); if (i == 0) temp.Name = retString; else if (i == 1) temp.Longitude = float.Parse(retString); else if (i == 2) temp.Lattitude = float.Parse(retString); } returnedList.Add(temp); } DbReader.Close(); DbCommand.Dispose(); DbConnection.Close(); Centre[] ArrayofCentre = new Centre[returnedList.Count]; for (int i = 0; i < returnedList.Count; i++) { ArrayofCentre[i] = (Centre)returnedList[i]; } return ArrayofCentre; } [WebMethod] //[XmlInclude(typeof(Centre))] public String [] getCentreNames() { string MyConString = "DRIVER={MySQL ODBC 3.51 Driver};" + "SERVER=localhost;" + "DATABASE=Courier;" + "UID=root;" + "PASSWORD=password;" + "OPTION=3"; ArrayList returnedList = new ArrayList(); OdbcConnection DbConnection = new OdbcConnection(MyConString); DbConnection.Open(); OdbcCommand DbCommand = DbConnection.CreateCommand(); DbCommand.CommandText = "SELECT * FROM CENTRE"; OdbcDataReader DbReader = DbCommand.ExecuteReader(); string retString = "usual"; int fCount = DbReader.FieldCount; for (int i = 0; i < fCount; i++) { retString = DbReader.GetName(i); } while (DbReader.Read()) { string namestring=""; for (int i = 0; i < fCount; i++) { retString = DbReader.GetString(i); if (i == 0) namestring = retString; } returnedList.Add(namestring); } DbReader.Close(); DbCommand.Dispose(); DbConnection.Close(); String[] ArrayofString = new String[returnedList.Count]; for (int i = 0; i < returnedList.Count; i++) { ArrayofString[i] = (String)returnedList[i]; } return ArrayofString; } }