using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Web; using System.Web.Services; using System.Data.SqlClient; namespace RSSService { [WebService(Namespace="http://harbormist.com/", Description = "A web service to read a database table (RssFeeds)." + " [Original programmers: Hsiao-Chun Tang, Lin-Hung Wu; further developed by Pat Palmer]")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class RSSService : System.Web.Services.WebService { private string connectionString = "packet size=4096;" + "user id=********;" + "data source=\"sql2k502.discountasp.net\";" + "persist security info=False;" + "initial catalog=SQL2005_229378_harbor;" + "password=********"; public RSSService() { InitializeComponent(); } #region VS.NET generated code private IContainer components = null; private void InitializeComponent() { } protected override void Dispose( bool disposing ) { if(disposing && components != null) { components.Dispose(); } base.Dispose(disposing); } #endregion [WebMethod(Description="Get all site names in the data base")] public string[] GetAllSiteNames() { try { ArrayList list = new ArrayList(); SqlConnection connection = new SqlConnection(connectionString); connection.Open(); SqlCommand command = new SqlCommand("SELECT * FROM RssFeeds", connection); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) list.Add(reader.GetString(0)); reader.Close(); connection.Close(); return list.ToArray(typeof(string)) as string[]; } catch (Exception ex) { string[] myStringArray = { "Cannot locate feeds" }; return myStringArray; } } [WebMethod(Description="Get actual URL according to given site " + "name in the data base")] public string GetURL(string siteName) { try { SqlConnection connection = new SqlConnection(connectionString); connection.Open(); SqlCommand command = new SqlCommand("SELECT URL FROM RssFeeds WHERE " + "NAME = '" + siteName + "'", connection); string url = command.ExecuteScalar() as string; connection.Close(); return url; } catch (Exception ex) { return "Cannot locate feed"; } } } }