Milly Haywire

Milly Haywire

  • NA
  • 4
  • 3.5k

WebService and CSV Files

Nov 20 2013 5:06 PM
Hi, 

I'm trying to create a webservice that uses a dictionary class. The webservice is meant to take words from the dictionary and then give their meaning. When one word is input the meaning of that word is to be taken from the file. This is my current code but when I run it the meaning of the word chosen doesn't appear as the output. I get no output. 

This is the code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace MyWebService
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class Service1 : System.Web.Services.WebService
    {

        [WebMethod]
        public class Table
        {
            private Dictionary<string, string> _regionTimeValues = new Dictionary<string, string>();
            private String _words;

            public Table(String words)
            {
                _words = words;
            }

            public void AddValue(string key, string value)
            {
                _wordsTimeValues.Add(key, value);
            }
        }

        public class Program
        {
            static void Main(string[] args)
            {
                Dictionary<string, Table> tables = new Dictionary<string, Table>();

                using (var reader = new StreamReader("Data.csv"))
                {
                    // First line contains column names.
                    var columnNames = reader.ReadLine().Split(',');
                    for (int i = 1; i < columnNames.Length; ++i)
                    {
                        var columnName = columnNames[i];
                        tables.Add(columnName, new Table(columnName));
                    }

                    var line = reader.ReadLine();
                    while (line != null)
                    {
                        var columns = line.Split(',');

                        for (int i = 1; i < columns.Length; ++i)
                        {
                            var table = tables[columnNames[i]];
                            table.AddValue(columns[0], double.Parse(columns[i]));
                        }

                        line = reader.ReadLine();
                    }
                }
            }
        }
    }
}
If anyone can tell me where I'm going wrong that would be great. Thank you. 
Milly