2013-11-20 48 views
1

嗨大家抱歉打扰你。我运行一个小博客,我只是试图创建一个web服务,允许输入单词并显示其意义。我最近在C#代码中自学成功,认为自己越来越好,但我遇到了一些困难。这是我目前的工作代码;CSV文件和Web服务

SORRY JUST NOTICED HAD COPY/PASTED WRONG CODE。更新的IT NOW

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(); 
        } 
       } 
      } 
     } 
    } 
} 

我想,因为我也有类似的应用程序控制台应用程序中工作,但试图做它在一个web服务可以将其用作移动从一个应用程序代码到另一个简单已经把我拉我的头发。

+1

究竟是什么? –

+1

这甚至编译? getWords()中的'words'是什么?而'public string words()'似乎没有返回任何东西。 –

+0

你期待这些方法做什么?正如他们目前的立场,应用程序不会编译,更不用说运行。 'words()'方法不返回值,'getWords()'引用一个尚未定义的变量。 – Kami

回答

0

您的代码将控制台应用程序代码与Web应用程序代码混合在一起。两者运行方式不同。

在最基本的意义上,

控制台应用程序所需的方法通常static void Main()这是第一种方法运行的应用程序启动时。

Web应用程序只运行给定页面上对应于请求操作的方法。

你有一个网页中的控制台应用程序的代码,这不会通过简单的复制粘贴工作。你需要修改代码。您提供的代码样本目的不明确,所以我无法为您提供样本。