Reputation: 36058
I have the following web service:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class Test : System.Web.Services.WebService
{
[WebMethod(EnableSession=true)]
public void SetSession()
{
HttpContext.Current.Session["Test"] = true;
}
[WebMethod(EnableSession = true)]
public bool IsSessionSaved()
{
var temp = HttpContext.Current.Session["Test"];
return temp != null;
}
}
Note I have the EnableSession = true
.
On my client I have added a Web Service Reference NOT a Service Reference.
Note: In order to create a web service reference instead of the default service reference that visual studio adds for you I followed this steps.
and on my client console appication I have:
var client = new Test();
client.SetSession();
bool isSessionSaved = client.IsSessionSaved();
Why is isSessionSaved = false
?
Update: I don't think the problem is in the web service it works if I invoke the methods through the default website. I am sure the client is not saving the cookies. Perhaps I need a cookie aware client. I might need to modify the client.
Upvotes: 0
Views: 311
Reputation: 167
Session state runs off of the session cookie, in order to support cookies you need to add a cookie container to your soap client.
CookieContainer cookieJar = new CookieContainer();
client.CookieContainer = cookieJar;
On a WCF service client the equivalent would be setting allowCookies="true" on the httpbinding configuration.
Upvotes: 1
Reputation: 3751
You have to install Session configuration on IIS.
This is the link: http://technet.microsoft.com/en-us/library/cc725624(v=ws.10).aspx
Upvotes: 0