WebService有两个方法:
[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客户端:
System.Net.CookieContainer cc = new System.Net.CookieContainer();
Service service = new Service(); // Service 是引用webservice时生成代理类
service .CookieContainer = cc;
Rerference
http://apps.hi.baidu.com/share/detail/17144083
http://www.codeproject.com/KB/session/SessionWithWS.aspx

本文介绍了如何在WinForm客户端中启用Session来调用启用Session的WebService。通过设置Service代理类的CookieContainer属性,确保登录状态在不同WebMethod间得以保持。详细步骤参考了多个技术论坛和资源。
3361

被折叠的 条评论
为什么被折叠?



