Skip to content

Use Session Enabled Webservice in WindowsForm.

public class MyService : System.Web.Services.WebService
{
 [WebMethod(EnableSession=true)]
 public void setMethod(bool value)
 {
  Session["myBoolVariable"] = value;
 }

 [WebMethod(EnableSession=true)]
 public bool getMethod()
 {
 return (bool)Session["myBoolVariable"];
 }
}

 

In above Webservice Session is used but in windows form application there is no any logic to use session so detect session of Windows Form or Console application we must need to create CookiesContainer. as below

 

private void myWinFormMethod()
{
 MyService myWebService = new MyService();
 myWebService.CookieContainer = new System.Net.CookieContainer();

 myWebService.setMethod( true ); // should be saved, if working
 bool myBoolVariable = myWebService.getMethod();
}

Leave a Reply

%d bloggers like this: