WinForm客户端调用 WebService时 如何启用Session
摘自: http://www.cnblogs.com/swtseaman/archive/2011/04/18/2020176.html
WebService有两个方法:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
[WebMethod(EnableSession = true )]
public bool Login( string strName)
{
Session[ "UserName" ] = strName;
}
[WebMethod(EnableSession = true )]
public string GetName()
{
if (Session[ "UserName" ] == null )
return "" ;
else
return Session[ "UserName" ].ToString();
}
//注意EnableSession=true属性
|
WinForm客户端:
1
2
3
4
|
System.Net.CookieContainer cc = new System.Net.CookieContainer();
Service service = new Service(); // Service 是引用webservice时生成代理类
service .CookieContainer = cc; |