使用CookieContainer
代码如下:
web server服务端:
[WebMethod(true)]
public void WriteSession(string text)
{
Session["a"] = text;
}
[WebMethod(true)]
public string ReadSession()
{
return Session["a"].ToString();
}
客户端:
System.Net.CookieContainer cc = new System.Net.CookieContainer(); localhost.WebService ws = new localhost.WebService(); ws.CookieContainer = cc; ws.WriteSession(TextBox1.Text); TextBox2.Text = ws.ReadSession();