[Mono-devel-list] Session not working in web services ?
Javier Ramon Garcia
javier at uh.cu
Wed Apr 28 13:52:44 EDT 2004
It seems that the Session container is not working even in simple web services
like this one.
Check this out: I have a file "Sum.asmx" which have a single line:
<%@ WebService Language="c#" Codebehind="Test.cs" Class="Util.Test" %>
In bin/Util.dll I have the class:
using System;
using System.Web;
using System.Web.Services;
using System.Web.SessionState;
namespace Util
{
public class Test: System.Web.Services.WebService
{
[ WebMethod(EnableSession=true) ]
public int AddOne()
{
if ( Session["counter"] == null )
{ Session["counter"]=0; }
else
{ Session["counter"]=(int)Session["counter"]+1; }
return (int)Session["counter"];
} // method
} // class
} // namespace
For testing this I'm using xsp.exe (version 0.12). After running xsp, and
opening my konqueror, I point to the Sum.asmx service, and go to the test
form. Then I press Invoke several time getting 0 all times. I think this is
an error.
The examples that comes with xsp don't make use of Session, instead they use
static variables (!?). I modify session1.aspx this way(see below) and then
it worked, however it's not the same case: this is a aspx not an asmx, and
the code is embeded in the aspx, it's not in a dll.
Thanks in advance for helping.
Javier.
<%@ language="C#" %>
<html>
<script runat=server>
void Clicked (object sender, EventArgs e)
{
if ( Session["counter"] == null ) { Session["counter"] = 0; }
Session["counter"] = (int)Session["counter"] + 1;
uno.InnerText = String.Format ("Button clicked {0} times.",
Session["counter"] );
}
</script>
<head>
<title>Session Test</title>
</head>
<body>
<form runat="server">
<asp:Button id="btn" Text="Submit" OnClick="Clicked" runat="server"/>
<span runat=server id="uno"></span>
</form>
</body>
</html>
More information about the Mono-devel-list
mailing list