WebService简单示例

记录一下,以备后用:

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


namespace Niunan.ZZ.JKDA.Web.webservice
{
    /// <summary>
    /// GGService 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://gxbest.cn/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
    // [System.Web.Script.Services.ScriptService]
    public class GGService : System.Web.Services.WebService
    {
        public Credentials token; 


        /// <summary>
        /// 获取全部公告
        /// </summary>
        /// <returns></returns>
        [WebMethod(Description = "获取全部公告")]
        [SoapHeader("token", Direction = SoapHeaderDirection.In)] 
        public List<Niunan.ZZ.JKDA.Model.S_GongGao> GetGongGao() {
            if (token.AccountID != "admin" || token.PIN != "admin")
            {
                return null;
            } 
            return new Niunan.ZZ.JKDA.DAL.S_GongGaoDAO().GetListArray("");
        }


        /// <summary> 
        /// 用于web service的安全性
        /// </summary> 
        public class Credentials : System.Web.Services.Protocols.SoapHeader
        {
            public string AccountID;
            public string PIN;
        } 


    }
}

 添加了web引用后,下面是提取示例:

            cn.gxbest.GGService ws = new Niunan.ZZ.JKDA.Web.cn.gxbest.GGService();
            ws.CredentialsValue = new Niunan.ZZ.JKDA.Web.cn.gxbest.Credentials() { AccountID = "admin", PIN = "admin" };
            cn.gxbest.S_GongGao[] gg = ws.GetGongGao();
            List<cn.gxbest.S_GongGao> list = new List<cn.gxbest.S_GongGao>();


            foreach (cn.gxbest.S_GongGao item in gg)
            {
                list.Add(item);
            }
            GridView1.DataSource = list;
            GridView1.DataBind();
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值