zoukankan      html  css  js  c++  java
  • 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();
    撸码:复制、粘贴,拿起键盘就是“干”!!!
  • 相关阅读:
    mysql主从备份案例—读写分离(异步主从)
    MySQL 汉化+完全备份操作实例
    Linux指令和shell脚本
    文件压缩和打包
    文件系统格式化和挂载
    linux常用指令和一些选项的汇总
    linux文件权限和群组
    [windows][技巧]百度网盘提示您的电脑已安装百度网盘,是否覆盖,解决方法
    [html][js]视频倍速播放功能
    [julia][学习笔记]julia的安装
  • 原文地址:https://www.cnblogs.com/niunan/p/1791525.html
Copyright © 2011-2022 走看看