秀纳

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
WebService的Sesinon保存利用的是Cookie
例子:
ClientForm:
 1    public partial class Form1 : Form
 2    {
 3        CookieContainer mycookie = new CookieContainer();
 4        showna.Service myService = new showna.Service();
 5     
 6        public Form1()
 7        {
 8            InitializeComponent();
 9        }

10
11        private void button1_Click(object sender, EventArgs e)
12        {
13            myService.CookieContainer = mycookie;//必须要有一个CookieContainer保存Seesion
14           textBox1.Text = myService.SessionHitCounter().ToString();
15        }

16    }

WebService:
   [ WebMethod(Description="Per session Hit Counter",EnableSession=true)]//EnableSession必须为True
    public int SessionHitCounter() {
       
if (Session["HitCounter"== null{
          Session[
"HitCounter"= 1;
       }

       
else {
          Session[
"HitCounter"= ((int) Session["HitCounter"]) + 1;
          }

       
return ((int) Session["HitCounter"]);
    }
posted on 2006-10-18 10:23  秀纳  阅读(2333)  评论(2)    收藏  举报