WinForm客户端调用 WebService时 如何启用Session

来源:互联网 发布:js设置select选中值 编辑:程序博客网 时间:2024/06/13 06:08

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://social.microsoft.com/Forums/hu-HU/xmlwebserviceszhchs/thread/5aefe998-668e-49d0-bbd0-0cc4320729c8

http://www.codeproject.com/KB/session/SessionWithWS.aspx




原创粉丝点击