473,406 Members | 2,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

problems with WebService EnableSession in VS2005

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
Feb 15 '07 #1
4 3221
Hello Nadav,

As for the SessionID problem you meet in ASP.NET webservice call, it is
likely due to the sessionID lazy initializing feature in ASP.NET. For
ASP.NET sessionstate module, it will always assign a random sessionID for
each page request(event of the same client) if you haven't stored any data
in the SessionState. This can avoid allocating unused server-side
sessionstate storage. This has also be mentioned in the ASP.NET session FAQ:

#Understanding session state modes + FAQ
http://forums.asp.net/7504/ShowPost.aspx

Here is the original description picked from the FAQ:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Q: Why does the SessionID changes in every request?
A: This may happen if your application has never stored anything in the
session state. In this case, a new session state (with a new ID) is
created in every request, but is never saved because it contains nothing.

However, there are two exceptions to this same session ID behavior:
- If the user has used the same browser instance to request another page
that uses the session state, you will get the same session ID every time.
For details, see "Why does the SessionID remain the same after the Session
times out?"
- If the Session_OnStart event is used, ASP.NET will save the session state
even when it is empty.
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

therefore, for your scenario, your webservice may first store a small
placeholder data into session so as to make the sessionID fixed. You can
try testing it to see whether it works.

Hope this helps some.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Feb 16 '07 #2
Hi Steven,

I've tried it, and if I save something in the session then the session ID
remains the same.
So EnableSession=true DOES work with ASP.NET 2.0.
The thing I don't understand is that 'Understanding session state modes +
FAQ' page
last updated date is Sept 21, 2004.
So I would think that the page describes the behaiviour of asp.net 1.1.
However, in the VS2003 web service I got the session ID even if I didn't
save anything in the session.
Oh, Never mind. As long as it works with ASP.NET 2.0..
Thanks for your help.

Nadav

Feb 18 '07 #3
Thanks for your followup Nadav,

Yes, that FAQ article has been generaetd early at ASP.NET 1.x time. Most of
its implemenation feature and behavior applies for both ASP.NET 1.X and
2.0. For the session ID behvior, it does be consistent between ASP.NET 1.1
and 2.0 application(at least for webform application scenario). For the
webservice proxy of your VS 2003 webservice, I think there may already
exists some data in the server session or the ASP.NET 1.x webservice will
put some placeholder data whenever we enablesession for webservice. So far
I haven't got indepth on this.

Anyway, glad that you've got it working and if there is anything else we
can help, please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
Feb 19 '07 #4
Hi Steven,

I've come up to this article when searching information on keeping a
webservice 'alive'.

Let's say that we would use a webservice (ASP.NET 2.0 / IIS 5) for
authentication (using soapheaders) and then make further use of other methods
within the same webservice to expose data from our back-end system (where our
ERP/... is running) to our customers.

Would this be a good approach ? And do you know if we could use the session
for keeping the state of the currently authenticated user ?

Thanks for a reply.

Sincerely

Ivo

"Steven Cheng[MSFT]" wrote:
Thanks for your followup Nadav,

Yes, that FAQ article has been generaetd early at ASP.NET 1.x time. Most of
its implemenation feature and behavior applies for both ASP.NET 1.X and
2.0. For the session ID behvior, it does be consistent between ASP.NET 1.1
and 2.0 application(at least for webform application scenario). For the
webservice proxy of your VS 2003 webservice, I think there may already
exists some data in the server session or the ASP.NET 1.x webservice will
put some placeholder data whenever we enablesession for webservice. So far
I haven't got indepth on this.

Anyway, glad that you've got it working and if there is anything else we
can help, please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights
Mar 2 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: jhcorey | last post by:
I'm having some difficulty trying to figure out how to do this. The help topics seem to be still referring to VS2003 In VS2003 (1) I get the webservice reference. (2) I add using...
0
by: frankgerlach | last post by:
When trying to run the sample web services of the mono distribution (file /opt/mono-1.1.10/lib/xsp/test/1.1/webservice/TestService.asmx), I get the following error message in my web browser: ...
1
by: Thorsten | last post by:
Hi, I try to use the WebService from MS CRM 3.0 but I always get a Time-out. So I make a really simple testapp which uses the following code: --------- CrmService.CrmService service = new...
1
by: Stefano Magni | last post by:
Hi all, Is it possible debug my WebService that I've published under IIS WebServer ? The default permit to debug only in ASP.NET Develepment WebServer. Thanks Stefano
2
by: Michael E Baltic | last post by:
VS 2005 allows for web sites and services to be run without installing IIS. What if I want to create a SOA application for a non-internet connected environment? For example: I have a pc running...
0
by: rob | last post by:
I am trying to debug a webservice by steping into a web method called from a windows form project. The strange thing is that sometimes it works but often it does not. When it does not work I get...
4
by: Bit Byte | last post by:
I'm having problem compiling one of my projects with VS2005. The problems arise with VS2005 (apparent?) inability to compile log4cpp. Has anyone succesfully compiled log4cpp using VS2005? Here...
0
by: Vids | last post by:
Hi, We are doing migration of web service from VS2003 to VS2005 After upgrading the project I m trying to add a web reference to the web service. While adding web reference it shows all the web...
2
by: xpnctoc | last post by:
Hello, Does anyone know anything about problems with running VS2005 / VS2005B2 side-by-side? When I installed 2008B2, it seemed to break a number of things in 2005. Consider: I have an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.