Hi everybody,
I've got two questions about using the EnableSession property with an
ASP.NET WebService:
First Question:
I'm trying to create a web service with EnableSession=t rue.
I can't get it to work with VS2005 ( It works with vs2003!).
Here is my testcase:
I created two web services (hosted on IIS on the same computer).
One WebService was created using VS2005:
[WebMethod(Enabl eSession=true)]
public string GetSessionID()
{
return this.Context.Se ssion.SessionID ;
}
The other was created using VS2003:
[WebMethod(true)]
public string GetSessionID()
{
return this.Context.Se ssion.SessionID ;
}
Then I created a simple WinForms application (with 1 button and 1 listbox):
public partial class Form1 : Form
{
public Form1()
{
InitializeCompo nent();
}
// this is the web reference to the VS2005 web service.
localhost.Servi ce srv=new TestWebServiceS ession2.localho st.Service();
CookieContainer cookies=new CookieContainer ();
// this is the web reference to the VS2003 web service.
localhost1.Serv ice1 srv1=new
TestWebServiceS ession2.localho st1.Service1();
CookieContainer cookies1=new CookieContainer ();
private void button1_Click( object sender, EventArgs e )
{
srv.CookieConta iner=cookies;
string s=srv.GetSessio nID();
listBox1.Items. Add(s);
srv1.CookieCont ainer=cookies1;
s=srv1.GetSessi onID();
listBox1.Items. Add("*"+s);
}
}
When I click on the button the program calls both web services and adds the
session IDs returned to the listbox.
I can see that the VS2003 webservice returns the same session id everytime.
The VS2005 returns a different session ID.
I called the web services from IExplorer when Fiddler running and I see that
the VS2003 web service returns a cookie:
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.1
Date: Thu, 15 Feb 2007 08:34:14 GMT
X-Powered-By: ASP.NET
X-AspNet-Version: 1.1.4322
Set-Cookie: ASP.NET_Session Id=zbextf45fder t255admh01na; path=/
Cache-Control: private, max-age=0
Content-Type: text/xml; charset=utf-8
Content-Length: 109
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">zbextf45fdert 255admh01na</string>
The VS2005 web service does NOT return a cookie:
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.1
Date: Thu, 15 Feb 2007 08:20:39 GMT
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Cache-Control: private, max-age=0
Content-Type: text/xml; charset=utf-8
Content-Length: 109
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">1l5ccq2mktsfv 0342j5hxa45</string>
Am I doing something wrong or is is a problem with ASP.NET 2.0?
Second Question:
The cookie that stores the session id is asp.net specific, right?
So if I need to write a web service (given a WSDL) to work with a certain
application (which I didn't write)
I can't make the web service session enabled because the application will
not send the cookie ?
Thanks,
Nadav