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=true.
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(EnableSession=true)]
public string GetSessionID()
{
return this.Context.Session.SessionID;
}
The other was created using VS2003:
[WebMethod(true)]
public string GetSessionID()
{
return this.Context.Session.SessionID;
}
Then I created a simple WinForms application (with 1 button and 1 listbox):
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
// this is the web reference to the VS2005 web service.
localhost.Service srv=new TestWebServiceSession2.localhost.Service();
CookieContainer cookies=new CookieContainer();
// this is the web reference to the VS2003 web service.
localhost1.Service1 srv1=new
TestWebServiceSession2.localhost1.Service1();
CookieContainer cookies1=new CookieContainer();
private void button1_Click( object sender, EventArgs e )
{
srv.CookieContainer=cookies;
string s=srv.GetSessionID();
listBox1.Items.Add(s);
srv1.CookieContainer=cookies1;
s=srv1.GetSessionID();
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_SessionId=zbextf45fdert255admh01na; 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/">zbextf45fdert255admh01na</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/">1l5ccq2mktsfv0342j5hxa45</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