我在服务器上有一个变量,想让它保存某一个页面的值。public string username;
客户端
localhost.Service1() ts = new localhost.Service1();
ts.CookieContainer = new System.Net.CookieContainer();
我把这两句放在构造函数或Page_Load里,可是每点击一次按钮,这两句都会被执行。
客户端一个按钮事件里调用setA("abc")
为什么另一个按钮里调用getA()却得不到abc?服务器端
[WebMethod (EnableSession=true)]
public string getA()
{
return (string)Session["username"];
}
[WebMethod (EnableSession=true)]
public void setA(string Value)
{
Session["username"] = Value;
}
客户端
localhost.Service1() ts = new localhost.Service1();
ts.CookieContainer = new System.Net.CookieContainer();
我把这两句放在构造函数或Page_Load里,可是每点击一次按钮,这两句都会被执行。
客户端一个按钮事件里调用setA("abc")
为什么另一个按钮里调用getA()却得不到abc?服务器端
[WebMethod (EnableSession=true)]
public string getA()
{
return (string)Session["username"];
}
[WebMethod (EnableSession=true)]
public void setA(string Value)
{
Session["username"] = Value;
}
2、应该有这样一个类:
public class YourServiceName : System.Web.Services.Protocols.SoapHttpClientProtocol
3、在其构造函数内添加:
this.CookieContainer = new CookieContainer();
CookieContainer cc = new CookieContainer();
ts.CookieContainer = cc;
cc.Method1(......ts.CookieContainer = cc;
cc.Method2(...保持对同一个CookieContainer引用
CookieContainer cc = new CookieContainer();
ts.CookieContainer = cc;
ts.Method1(......ts.CookieContainer = cc;
ts.Method2(...保持对同一个CookieContainer的引用
不对呀。ServieceName应该是继承System.Web.Services.WebService
里面没这个属性CookieContainer