WinForm客户端调用 WebService时 如何启用Session
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;