Showing posts with label session. Show all posts
Showing posts with label session. Show all posts

Wednesday, December 10, 2008

WGWCF 使用session

在binding中設定好ReliableSession.enabled = True即可

 

另外在Contract中,可以設定SessionMode=SessionMode.Requied

[ServiceContract(Name = "IWGWCF", SessionMode = SessionMode.Required)]
public interface IWGWCF
{
[OperationContract]
string search(string keyword, int start, int returnCount);


}

在behavior中可以設定session使用的時間周期

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
public class WGWCF : IWGWCF
{
public string search(){

}
}

Thursday, November 27, 2008

web service 使用Session

web service中使用session需要開啟EnableSession
[WebMethod(EnableSession = true, CacheDuration=0....)]

web.config中<sessionState mode="">  mode不等於none

 

.NET中session的方式是透過Cookie儲存ID,才可以延續使用。
如果是在Web service中使用session,會來存取web service就不一定是瀏覽器
可能是程式碼。

如果是程式碼的話,則需要在程式碼中使用CookieContainer

WebService ws = new WebService();
System.Net.CookieContainer container = new System.Net.CookieContainer();

ws.CookieContainer = container ;
ws.XXXX();

CookieContainer 中會保存server端傳回來的sessionId,所以就可以延續的使用。

如果有需要的話,也是可以把CookieContainer存起來,再傳到需要使用的網頁或其他程式碼。