webservice结合dhtml的简单例子(一,webservice)

dhtml|web

    前段事件在网上看到一个基于web的财务系统,它是通过activex实现的,实际上如果用webservice结合dhtml,那完全可以抛开activex。下面是个简单的例子。
首先是webservice , 很简单,我就不详细说明了,看注释就可以了。

文件 study.asmx.cs

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using System.Xml.Serialization ;

namespace StudyXML
{
    /// <summary>
    /// <br>一个webservice的例子</br>
    /// <br>Author:Bigeagle@163.net</br>
    /// <br>Date:  2001/12/21</br>
    /// <br>History: 2001//12/21完成</br>
    /// </summary>
    /// <remarks>
    /// 这个webservice实现的功能很简单
    /// 主要功能有两个,一个是取得预定义的Item数组
    /// 另一个是保存Record类型的纪录
    /// </remarks>
    public class Study : System.Web.Services.WebService
    {
        
        private ArrayList m_arrItems ;

        private ArrayList m_arrReocrds ;

        public Study()
        {
            //CODEGEN: This call is required by the ASP.NET Web Services Designer
            InitializeComponent();
            this.m_arrReocrds = new ArrayList() ;

            this.m_arrItems = new ArrayList() ;

            //增加一些实验数据
            for(int i = 0 ; i < 100 ; i ++)
            {
                this.m_arrItems.Add(new Item("ItemName" + i.ToString()
                    , "ItemValue" + (i + 1).ToString())) ;
            }

            
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="a_strItemName">Item name</param>
        /// <returns>Item对象</returns>
        private Item GetItem(string a_strItemName)
        {
            //throw(new Exception(Server.UrlDecode(a_strItemName))) ;
            for(int i = 0 ; i < this.m_arrItems.Count ; i ++)
            {
                Item item = (Item)this.m_arrItems[i] ;
                if(item.Name == Server.UrlDecode(a_strItemName).Trim())
                {
                    return item ;
                }
            }

            return null ;
        }

        #region Component Designer generated code
        
        //Required by the Web Services Designer
        private IContainer components = null;
                
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if(disposing && components != null)
            {
                components.Dispose();
            }
            base.Dispose(disposing);        
        }
        
        #endregion

        [WebMethod]
        public void AddItem(string a_strName , string a_strValue)
        {
            this.m_arrItems.Add(new Item(a_strName , a_strValue));
        }

        /// <summary>
        /// 取得Item列表
        /// </summary>
        /// <returns>arraylist</returns>
        [WebMethod]
        [XmlInclude(typeof(Item))]
        public ArrayList GetItems()
        {
            return this.m_arrItems ;
        }

        /// <summary>
        ///  保存纪录
        /// </summary>
        /// <param name="a_strItemName"></param>
        /// <param name="a_strDemoName"></param>
        /// <param name="a_intDemoAmount"></param>
        /// <returns>如果成功返回false,否则返回false</returns>
        [WebMethod]
        public bool SaveRecord(string a_strItemName
            , string a_strDemoName , int a_intDemoAmount)
        {
            try
            {
                Item item = this.GetItem(a_strItemName) ;
                if(item != null)
                {
                    this.m_arrReocrds.Add(new Record(this.m_arrReocrds.Count + 1
                        , item
                        , new Demo(a_strDemoName , a_intDemoAmount))) ;
                }
                else
                {
                    throw(new Exception("指定Item的Name错误!")) ;
                }
                return true ;
            }
            catch(Exception e)
            {
                throw(new Exception(e.ToString())) ;
                //return false ;
            }
        }//end method
    }//end class

    /// <summary>
    /// 一个简单的类,用来对应象select的option这类东西
    /// </summary>
    public class Item
    {
        private string m_strName ;
        private string m_strValue ;

        public string Name
        {
            get
            {
                return this.m_strName ;
            }
            set
            {
                this.m_strName = value ;
            }
        }

        public string Value
        {
            get
            {
                return this.m_strValue ;
            }
            set
            {
                this.m_strValue = value ;
            }
        }

        public Item(string a_strName , string a_strValue)
        {
            this.m_strName = a_strName ;
            this.m_strValue = a_strValue ;
        }
        public Item()
        {
            this.m_strName = "" ;
            this.m_strValue = "" ;
        }
    }//end class

    /// <summary>
    /// 简单的示例用类
    /// 结构很简单,三个成员变量
    /// 一个int类型的编号,
    /// 一个item类型,一个Demo类型
    /// </summary>
    public class Record
    {
        private int m_intID ;
        private Item m_objMyItem ;
        private Demo m_objMyDemo ;

        public Record()
        {
            this.m_intID = 0 ;
            this.m_objMyDemo = new Demo() ;
            this.m_objMyItem = new Item() ;
        }

        public Record(int a_intID , Item a_objItem , Demo a_objDemo)
        {
            this.m_intID = a_intID ;
            this.m_objMyDemo = a_objDemo ;
            this.m_objMyItem = a_objItem ;
        }
    }//end calss

    /// <summary>
    /// 一个简单的示例用类
    /// 结构很简单,只有两个成员变量,一个name , 一个amount
    /// </summary>
    public class Demo
    {
        private string m_strName ;
        private int m_intAmount ;
        
        public string Name
        {
            get
            {
                return this.m_strName ;
            }
            set
            {
                this.m_strName = value ;
            }

        }

        public int Amount
        {
            get
            {
                return this.m_intAmount ;
            }
            set
            {
                this.m_intAmount = value ;
            }
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        public Demo()
        {
            this.m_intAmount = 0 ;
            this.m_strName = "" ;
        }

        /// <summary>
        /// 重载构造函数
        /// </summary>
        /// <param name="a_strName"></param>
        /// <param name="a_intAmount"></param>
        public Demo(string a_strName , int a_intAmount)
        {
            this.m_intAmount = a_intAmount ;
            this.m_strName = a_strName ;
        }

    }//end class

}//end namespace

时间: 2024-10-29 11:35:21

webservice结合dhtml的简单例子(一,webservice)的相关文章

webservice结合dhtml的简单例子(三,漏贴一个文件,呵呵)

dhtml|web file demo.html <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" ><HTML>    <HEAD>        <META NAME="GENERATOR" Content="Microsoft Visual Studio 7.0">        <TITLE></TI

webservice结合dthml的简单例子(二,dhtml)

dhtml|web   客户端之所以使用dhtml,主要是为了实现remote,简单地说就是要达到无刷新的效果. 文件:study.htm <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" ><HTML>    <HEAD>        <TITLE></TITLE>        <META NAME="GENERATOR"

那位高手有WebService能跑起来的例子

问题描述 那位高手有WebService能跑起来的例子 刚刚接触这个 那位仁兄 有能跑起来的 代码 给我参考下 谢谢啦 解决方案 请看看这篇博文,有什么不明白的可以问我.http://jadethao.iteye.com/blog/1706963希望你能自己动手完成.毕竟自己弄出来能学到很多东西,还能有成就感.若正想要现成的,我这有!解决方案二:一分钟速成webservice,http://java-frog.iteye.com/admin/blogs/808412解决方案三:现在人们提到web

JQuery Ajax WebService传递参数的简单实例_jquery

Asp.NET中利用jQuery实现Ajax时,在服务器端可以使用aspx,ashx,以及WebService等方式.最近研究了一下WebService方式,jQuery Ajax 方法调用 jQuery Ajax方法调用 Asp.Net WebService 的详细实例代码这篇帖子给出了很详细的例子,不过没有给出详细解释.其中有几个细节问题开始没注意,费老劲才调通: 1)客户端data数据中的key字段名称必须和服务器端方法参数严格一致. 如客户端: //有参数调用 $(document).r

关于webservice的异步调用简单实例

web|异步 关于webservice的异步调用简单实例无论在任何情况下,被调用方的代码无论是被异步调用还是同步调用的情况下,被调用方的代码都是一样的, 下面,我们就以异步调用一个webservice 为例作说明.这是一个webservice <WebMethod(Description:="试验")> _ Public Function delCurTable(ByVal tbName As String) As Boolean Try Return True Catch

php添加数据到xml文件的简单例子_php实例

xml文件:stu.xml: <?xml version="1.0" encoding="utf-8" ?> <AllData> <xueshengmen> <xuesheng> <name>张三</name> <yuwen>80</yuwen> <shuxue>90</shuxue> <yingyu>70</yingyu>

php99乘法表:php简单例子--打印出99乘法表

php简单例子--打印出99乘法表:<?php//php打印出九九乘法表for ($i=1; $i<10; $i++){for ($j=1; $j<=$i; $j++){echo $j*$i;echo ' ';}echo '<br />';}?> 本文链接http://www.cxybl.com/html/wlbc/Php/20130326/37405.html

web.config文件自定义配置节的使用方法的一个简单例子

web web.config文件自定义配置节的使用方法的一个简单例子用来演示的程序名为MyApp,Namespace也是MyApp 1.编辑web.config文件 添加以下内容,声明一个Section <configSections>    <section name="AppConfig" type="MyApp.AppConfig, MyApp" /> </configSections>   声明了一个叫AppConfig的

SYBAES ASE 12.0 上一个横表转纵表的简单例子

SYBAES ASE 12.0 上一个横表转纵表的简单例子   千千如梦 2002年10月   /* create table ... */create table #dest_table(                         Flag char(1),                         A int null,                         B int null,                         C int null,