Hi,

I try to run a simple example of stateful web service. This example run well on
windows with Explorer and IIS but no on Mono with mod_mono+Apache, why?

In order to maintain stateful communication between a client application and a
server application,I use session objects and the cookie container.
On the Server I must explicitly enable session support for each Web service
method that requires a session state ( [WebMethod ( EnableSession = true )] )
On the Client application, I use cookie http with
System.Web.SessionState.HttpSessionState and System.Net.CookieContainer
classes.
When the web service method uses a session state, a cookie is passed back to
the Web Service client in the response header. 
That cookie uniquely identifies the session for that Web Service client.
To receive that cookie for the web service client, a new instance of
CookieContainer must be created and then assigned to the CookieContainer
property before the Web service method is called.
This make sure that the cookie is correctly included in subsequent requests. 
I must do this because I must store the cookies that are received in the session
state for future retrieval by the session.

The Web services code is: Contatore.asmx.cs
The client application code is: CounterCLI.aspx.cs

Could anybody help me please?

Thanks a lot,

Valentina.
{\rtf1\ansi\ansicpg1252\deff0\deflang1040\deftab708{\fonttbl{\f0\fmodern\fcharset0 Courier New;}{\f1\froman\fcharset0 Times New Roman;}} {\colortbl ;\red0\green0\blue255;\red127\green127\blue127;\red0\green127\blue0;} {\*\generator Msftedit 5.41.15.1503;}\viewkind4\uc1\pard\cf1\lang2057\f0\fs20 using\cf0 System;\par \cf1 using\cf0 System.Collections;\par \cf1 using\cf0 System.ComponentModel;\par \cf1 using\cf0 System.Data;\par \cf1 using\cf0 System.Diagnostics;\par \cf1 using\cf0 System.Web;\par \cf1 using\cf0 System.Web.Services;\par \par \cf1 namespace\cf0 Contatore\par \{\par \tab\cf2\par \cf0\tab\cf1 public\cf0 \cf1 class\cf0 Service1 : System.Web.Services.WebService\par \tab\{\par \tab\tab\cf1 public\cf0 Service1()\par \tab\tab\{\par \tab\tab\tab\cf3\par \cf0\tab\tab\tab InitializeComponent();\par \tab\tab\}\par \par \cf1\tab\tab #region\cf0 Component Designer generated code\par \tab\tab\par \tab\tab\cf3\par \cf0\tab\tab\cf1 private\cf0 IContainer components = \cf1 null\cf0 ;\par \tab\tab\tab\tab\par \tab\tab\cf2\par \cf0\tab\tab\cf1 private\cf0 \cf1 void\cf0 InitializeComponent()\par \tab\tab\{\par \tab\tab\}\par \par \tab\tab\cf2\par \cf0\tab\tab\cf1 protected\cf0 \cf1 override\cf0 \cf1 void\cf0 Dispose( \cf1 bool\cf0 disposing )\par \tab\tab\lang1040\{\par \tab\tab\tab\cf1 if\cf0 (disposing && components != \cf1 null\cf0 )\par \tab\tab\tab\{\par \tab\tab\tab\tab components.Dispose();\par \tab\tab\tab\}\par \tab\tab\tab\cf1 base\cf0 .Dispose(disposing);\tab\tab\par \tab\tab\lang2057\}\par \tab\tab\par \cf1\tab\tab #endregion\par \par \cf0\tab\tab\par \tab\tab\par \tab\tab [ WebMethod(Description="Per session Hit Counter",EnableSession=\cf1 true\cf0 )]\par \tab\tab\cf1 public\cf0 \cf1 int\cf0 SessionHitCounter() \par \tab\tab\{\par \tab\tab\tab\cf1 if\cf0 (Session["HitCounter"] == \cf1 null\cf0 ) \par \tab\tab\tab\{\par \tab\tab\tab\tab Session["HitCounter"] = 1;\par \tab\tab\tab\}\par \tab\tab\tab\cf1 else\cf0 \par \tab\tab\tab\{\par \tab\tab\tab\tab Session["HitCounter"] = ((\cf1 int\cf0 ) Session["HitCounter"]) + 1;\par \tab\tab\tab\lang1040\}\par \tab\tab\tab\cf1 return\cf0 ((\cf1 int\cf0 ) Session["HitCounter"]);\par \tab\tab\} \par \tab\}\par \}\par \par \par \f1\fs24\par } {\rtf1\ansi\ansicpg1252\deff0\deflang1040\deftab708{\fonttbl{\f0\fmodern\fcharset0 Courier New;}{\f1\froman\fcharset0 Times New Roman;}} {\colortbl ;\red0\green0\blue255;\red127\green127\blue127;\red0\green127\blue0;} {\*\generator Msftedit 5.41.15.1503;}\viewkind4\uc1\pard\cf1\lang2057\f0\fs20 using\cf0 System;\par \cf1 using\cf0 System.Collections;\par \cf1 using\cf0 System.ComponentModel;\par \cf1 using\cf0 System.Data;\par \cf1 using\cf0 System.Drawing;\par \cf1 using\cf0 System.Web;\par \cf1 using\cf0 System.Web.SessionState;\par \cf1 using\cf0 System.Web.UI;\par \cf1 using\cf0 System.Web.UI.WebControls;\par \cf1 using\cf0 System.Web.UI.HtmlControls;\par \cf1 using\cf0 System.Net;\par \par \cf1 namespace\cf0 CounterCLI\par \{\par \tab\cf2\par \cf0\tab\cf1 public\cf0 \cf1 class\cf0 WebForm1 : System.Web.UI.Page\par \tab\{\par \tab\tab\cf1 protected\cf0 System.Web.UI.WebControls.Label Label1;\par \tab\tab\cf1 protected\cf0 System.Web.UI.WebControls.Button Button1;\par \tab\par \tab\tab\cf3 // Create a new instance of a proxy class for your XML Web service.\par \cf0\tab\tab\cf1 private\cf0 ServerUsage.Service1 su = \cf1 new\cf0 ServerUsage.Service1();\par \tab\tab\cf1 private\cf0 CookieContainer cookieJar;\par \par \par \tab\tab\cf1 private\cf0 \cf1 void\cf0 Page_Load(\cf1 object\cf0 sender, System.EventArgs e)\par \tab\tab\{\par \tab\tab\tab\cf3 // Put user code to initialize the page here\par \cf0\tab\tab\}\par \par \cf1\tab\tab #region\cf0 Web Form Designer generated code\par \tab\tab\cf1 override\cf0 \cf1 protected\cf0 \cf1 void\cf0 OnInit(EventArgs e)\par \tab\tab\{\par \tab\tab\tab\cf3\par \cf0\tab\tab\tab InitializeComponent();\par \tab\tab\tab\cf1 base\cf0 .OnInit(e);\par \tab\tab\}\par \tab\tab\par \tab\tab\cf2\par \cf0\tab\tab\cf1 private\cf0 \cf1 void\cf0 InitializeComponent()\par \tab\tab\{ \par \tab\tab\tab\cf1 this\cf0 .Button1.Click += \cf1 new\cf0 System.EventHandler(\cf1 this\cf0 .Button1_Click);\par \tab\tab\tab\cf1 this\cf0 .Load += \cf1 new\cf0 System.EventHandler(\cf1 this\cf0 .Page_Load);\par \par \tab\tab\lang1040\}\par \cf1\tab\tab\lang2057 #endregion\par \par \cf0\tab\tab\cf1 private\cf0 \cf1 void\cf0 Button1_Click(\cf1 object\cf0 sender, System.EventArgs e)\par \tab\tab\{\par \tab\tab\par \tab\tab\tab\par \tab\tab\tab\cf3 // Check to see if the cookies have already been saved for this session.\par \cf0\tab\tab\tab\cf1 if\cf0 (Session["CookieJar"] == \cf1 null\cf0 ) \par \tab\tab\tab\tab cookieJar= \cf1 new\cf0 CookieContainer();\par \tab\tab\tab\cf1 else\par \cf0\tab\tab\tab\tab cookieJar = (CookieContainer) Session["CookieJar"];\par \par \tab\tab\tab\cf3 // Assign the CookieContainer to the proxy class.\par \cf0\tab\tab\tab su.CookieContainer = cookieJar;\par \par \tab\tab\tab\cf3 // Invoke an XML Web service method that uses session state and thus cookies.\par \cf0\tab\tab\tab\cf1 int\cf0 count = su.SessionHitCounter(); \par \par \tab\tab\tab\cf3 // Store the cookies received in the session state for future retrieval by this session.\par \cf0\tab\tab\tab Session["CookieJar"] = cookieJar;\par \par \tab\tab\tab\cf3 // Populate the text box with the results from the call to the XML Web service method.\par \cf0\tab\tab\tab\lang1040 Label1.Text = count.ToString(); \par \tab\tab\par \par \tab\tab\}\par \tab\}\par \}\par \f1\fs24\par }

Reply via email to