zoukankan      html  css  js  c++  java
  • webService(1)

    using System;
    using System.Data;
    using System.Web;
    using System.Collections;
    using System.Web.Services;
    using System.Web.Services.Protocols;
    using System.ComponentModel;

    namespace Remoting
    {
        //2)在任意一个GetCollege()方法上部添加SoapDocumentMethod特性:

        //    [SoapDocumentMethod(Binding="OverloadedGetCollege")]
        //    [WebMethod(Description = "根据学号获得学生的学院", MessageName = "GetCollegeStuNum")]
        //    public string GetCollege(string strStuNum)

        /// <summary>
        /// Service1 的摘要说明
        /// </summary>
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1,Name="OverloadedGetCollege",EmitConformanceClaims=true )]
        [ToolboxItem(false)]
        public class Service1 : System.Web.Services.WebService
        {
            //构造并填充info数组
            string[,] strStuInfo ={
                        {"200511020120","贰零零五届","人文法律学院","社会工作","(1)班","无悔","1"},
                        {"200511020121","贰零零五届","人文法律学院","社会工作","(1)班","梁需","2"},
                        {"200511010122","贰零零五届","人文法律学院","法律专业","(1)班","陆磊","3"},
                        {"200511010220","贰零零五届","人文法律学院","法律专业","(2)班","白灵","4"},
                        {"200511010221","贰零零五届","人文法律学院","法律专业","(2)班","剑付","5"},
                        {"200511020222","贰零零五届","人文法律学院","社会工作","(2)班","敬意","6"},
                        {"200511100120","贰零零五届","化工生物学院","生物制药","(1)班","黄兴","7"},
                        {"200511100221","贰零零五届","化工生物学院","生物制药","(2)班","蕾蕾","8"},
                        {"200511100322","贰零零五届","化工生物学院","生物制药","(3)班","白冰","9"},
                        {"200611120120","贰零零六届","化工生物学院","发酵工程","(1)班","书并","10"},
                        {"200611120121","贰零零六届","化工生物学院","发酵工程","(1)班","小鱼","11"},
                        {"200611120421","贰零零六届","化工生物学院","发酵工程","(4)班","声声","12"},
                     };

            [WebMethod]
            public string HelloWorld()
            {
                return "Hello World";
            }

            [WebMethod(Description = "根据学号获得学生的姓名")]
            public string GetName(string strStuNum)
            {
                for (int i = 0; i < strStuInfo.GetLength(0); i++)
                {
                    if (string.Compare(strStuNum, strStuInfo[i, 0], true) == 0)
                        return strStuInfo[i, 5].ToString();
                }
                return "您输入的学号不存在";
            }

            [WebMethod(Description = "根据学号获得学生的专业和班级")]
            public string GetClass(string strStuNum)
            {
                for (int i = 0; i < strStuInfo.GetLength(0); i++)
                {
                    if (string.Compare(strStuNum, strStuInfo[i, 0], true) == 0)
                    {
                        return strStuInfo[i, 3].ToString() + strStuInfo[i, 4].ToString();
                    }
                }
                return "您输入的学号不存在";
            }

            [WebMethod(Description = "根据学号获得学生的入学时间")]
            public string GetYear(string strStuNum)
            {
                for (int i = 0; i < strStuInfo.GetLength(0); i++)
                {
                    if (string.Compare(strStuNum, strStuInfo[i, 0], true) == 0)
                    {
                        return strStuInfo[i, 1].ToString();
                    }
                }
                return "您输入的学号不存在";
            }

            [WebMethod(Description = "点击次数", EnableSession = true)]
            public int HitCounter()
            {
                if (Session["HitCounter"] == null)
                {
                    Session["HitCounter"] = 1;
                }
                else
                {
                    Session["HitCounter"] = ((int)Session["HitCounter"]) + 1;
                }
                return ((int)Session["HitCounter"]);
            }

            [WebMethod(Description = "根据学号获得学生的学院", MessageName = "GetCollegeStuNum")]
            public string GetCollege(string strStrNum)
            {
                for (int i = 0; i < strStuInfo.GetLength(0); i++)
                {
                    if (string.Compare(strStrNum, strStuInfo[i, 0], true) == 0)
                    {
                        return strStuInfo[i, 2].ToString();
                    }
                }
                return "您输入的学号不存在";
            }

            [WebMethod(Description = "根据排名获得学生的学员", MessageName = "GetCollegeStuRank")]
            public string GetCollege(int intStuRank)
            {
                for (int i = 0; i < strStuInfo.GetLength(0); i++)
                {
                    if (string.Compare(intStuRank.ToString(), strStuInfo[i, 6], true) == 0)
                    {
                        return strStuInfo[i, 2].ToString();
                    }
                }
                return "您输入的学生名不存在";
            }
        }
    }

  • 相关阅读:
    什么是JDBC的最佳实践?
    如何将jquery对象转换为js对象?
    JQuery有几种选择器?
    jQuery 库中的 $() 是什么
    JS 中 == 和 === 区别是什么?
    有两张表;请用SQL查询,所有的客户订单日期最新的前五条订单记录?
    根据你以往的经验简单叙述一下MYSQL的优化?
    数据库MySQL分页时用的语句?
    LeetCode231-2的幂(水题,考察是否粗心)
    LeetCode191-位1的个数(题目有问题)
  • 原文地址:https://www.cnblogs.com/daiweixm/p/1551697.html
Copyright © 2011-2022 走看看