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;
posted @ 2011-04-18 20:24  Crazy Coder  阅读(1925)  评论(0编辑  收藏  举报