ServerUsage su = new ServerUsage(); CookieContainer cookieJar; // Check to see if the cookies have already been saved for this session. if (Session["CookieJar"] == null) cookieJar= new CookieContainer(); else cookieJar = (CookieContainer) Session["CookieJar"]; // Assign the CookieContainer to the proxy class. su.CookieContainer = cookieJar; // Invoke an XML Web service method that uses session state and thus cookies. int count = su.PerSessionServiceUsage(); // Store the cookies received in the session state for future retrieval by this session. Session["CookieJar"] = cookieJar; // Populate the text box with the results from the call to the XML Web service method. SessionCount.Text = count.ToString();
In order to store session state in the ASP.NET HttpSessionState object, the XML Web service must inherit from WebService and a WebMethodAttribute applied to the XML Web service method, setting the EnableSession property to true. If session state is not needed for an XML Web service method, then disabling it may improve performance.
Web Service里调用不了session,必须将Session值与其他要传递的值组成字符串一起传入webmethod,然后将他分开后再调用;若要更改Session,可在Web Service的返回函数中处理。
就是一个 Cookie容器的问题了。。但是加入我的客户段不是浏览器的话
怎么获取浏览器的CookieContainer。。可是不知道怎么获取。
youws MyGame = new yourws();
MyGame.CookieContainer =new System.Net.CookieContainer(); // Session Cookie
而我的想法是 根浏览器 公用Session
CookieContainer cookieJar; // Check to see if the cookies have already been saved for this session.
if (Session["CookieJar"] == null)
cookieJar= new CookieContainer();
else
cookieJar = (CookieContainer) Session["CookieJar"]; // Assign the CookieContainer to the proxy class.
su.CookieContainer = cookieJar; // Invoke an XML Web service method that uses session state and thus cookies.
int count = su.PerSessionServiceUsage(); // Store the cookies received in the session state for future retrieval by this session.
Session["CookieJar"] = cookieJar; // Populate the text box with the results from the call to the XML Web service method.
SessionCount.Text = count.ToString();
解析WEB SERVICE中的状态管理 (2)http://developer.ccidnet.com/pub/article/c322_a32324_p3.html
解析WEB SERVICE中的状态管理 (3)