• 在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:     }
  • 相关阅读:
    能够免费做商业站点的CMS讨论
    ntoskrnl.exe损坏或丢失的解决方式
    QT 仓库管理系统 开放源代码
    Disposable microfluidic devices: fabrication, function, and application Gina S. Fiorini and Daniel T
    DllImport中的EntryPoint
    IOS Table中Cell的重用reuse机制分析
    双slave的server_uuid同样问题
    怎样使用SetTimer MFC 够具体
    2013 成都邀请赛
    设计模式六大原则(2):里氏替换原则
  • 原文地址:https://www.cnblogs.com/zhaox583132460/p/3621917.html
Copyright © 2020-2023  润新知