至高吴上(Alfa.wu)

一个人,一生,能坚持做好一件事情是多么的牛XX啊!!!

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

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;
 
posted on 2013-09-02 18:51  Alfa  阅读(323)  评论(0编辑  收藏  举报