WebService session保存
WebService的Sesinon保存利用的是Cookie
例子:
ClientForm:
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"]);
}
例子:
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
}

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

WebService:










转: http://www.cnblogs.com/showna/archive/2006/10/18/532184.html