zoukankan      html  css  js  c++  java
  • 在webservice中传递Hashtable

    < DOCTYPE html PUBLIC -WCDTD XHTML StrictEN httpwwwworgTRxhtmlDTDxhtml-strictdtd>
    webservice中不支持hashtable的数据类型,那么如何在webservice中传递hashtable呢?我们可以通过将hashtable转化为webservice中支持的数组的类型来进行传递,在调用的时候再转换成hashtable就可以了。
    [WebMethod]
        public DictionaryEntry[] SetValue()
        {
            Hashtable sl = new Hashtable();
            sl.Add("kiss", "me");
            sl.Add("love", "you");
            DictionaryEntry[] array = new DictionaryEntry[sl.Count];
            sl.CopyTo(array, 0);
            return array;
        }
    调用webservice中的方法

    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Collections;
    using SourceCode;
    using localhost;
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                getHashTable();
              }
          }

        private void getHashTable()
        {
            Hashtable obj = new Hashtable();
            localhost.WebService test = new localhost.WebService();
            localhost.DictionaryEntry[] entries = (localhost.DictionaryEntry[])test.SetValue();
            foreach (localhost.DictionaryEntry entry in entries)
            {
                   obj.Add(entry.Key, entry.Value);
            }
            foreach (System.Collections.DictionaryEntry each in obj)
            {
                Response.Write(each.Key.ToString() + "=" + each.Value.ToString() + "<br/>");
            }

        }
        }

    注:
    引用webservice的方法

    在 "项目 "单击右键-> "添加web引用 ",输入你的webservice地址,让系统帮你列出Url上可用的webservice,输入 "web 引用名 "-> "添加引用 "就可以了.
    剩下的和引用一个普通的dll就没什么大区别了.

  • 相关阅读:
    CSS标题省略号带后缀名称
    vue post下载
    PiNetwork – 国外手机挖矿,目前国外热度很高
    iview table expand 单击当前行控制
    iview 开关变化时控制状态的变更
    CSS伪元素before,after制作左右横线中间文字效果
    idea 修改代码自动编译
    如何获取微信公众号的关注链接?
    震惊,微信小程序可以设置网络字体!真香
    小程序字体大小怎么设置,小程序修改字体样式方法
  • 原文地址:https://www.cnblogs.com/netcorner/p/2911999.html
Copyright © 2011-2022 走看看