在webservice中传递Hashtable

webservice中不支持hashtable的数据类型,那么如何在webservice中传递hashtable呢?我们可以通过将hashtable转化为webservice中支持的数组的类型来进行传递,在调用的时候再转换成hashtable就可以了。

转载:http://www.cnblogs.com/emperoryong/archive/2009/09/13/1565902.html

   1: [WebMethod]
   2:     public DictionaryEntry[] SetValue()
   3:     {
   4:         Hashtable sl = new Hashtable();
   5:         sl.Add("kiss", "me");
   6:         sl.Add("love", "you");
   7:         DictionaryEntry[] array = new DictionaryEntry[sl.Count];
   8:         sl.CopyTo(array, 0);
   9:         return array;
  10:     }

调用webservice中的方法

   1: using System;
   2: using System.Data;
   3: using System.Configuration;
   4: using System.Web;
   5: using System.Web.Security;
   6: using System.Web.UI;
   7: using System.Web.UI.WebControls;
   8: using System.Web.UI.WebControls.WebParts;
   9: using System.Web.UI.HtmlControls;
  10: using System.Collections;
  11: using SourceCode;
  12: using localhost;
  13: public partial class _Default : System.Web.UI.Page
  14: {
  15:     protected void Page_Load(object sender, EventArgs e)
  16:     {
  17:         if (!IsPostBack)
  18:         {
  19:             getHashTable();
  20:          }
  21:       }
  22:  
  23:     private void getHashTable()
  24:     {
  25:         Hashtable obj = new Hashtable();
  26:         localhost.WebService test = new localhost.WebService();
  27:         localhost.DictionaryEntry[] entries = (localhost.DictionaryEntry[])test.SetValue();
  28:         foreach (localhost.DictionaryEntry entry in entries)
  29:         {
  30:                obj.Add(entry.Key, entry.Value);
  31:         }
  32:         foreach (System.Collections.DictionaryEntry each in obj)
  33:         {
  34:             Response.Write(each.Key.ToString() + "=" + each.Value.ToString() + "<br/>");
  35:         }
  36:  
  37:     }
  38:     }

在webservice中传递Hashtable,布布扣,bubuko.com

在webservice中传递Hashtable

上一篇:php中类的声明与使用


下一篇:前台jsp页面获取session对象