[Mono-list] WebService, SessionState and CookieContainer

beniniva@csr.unibo.it beniniva@csr.unibo.it
Mon, 26 Jul 2004 16:46:23 +0200


 Hi,
I try to run a simple example of stateful web service. This example run well on
windows with Explorer but no on Mono with 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:Service1.asmx.cs
--------------------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
...
...
...
[ WebMethod(Description="Per session Hit Counter",EnableSession=true)]
      public int SessionHitCounter()  
      {
    if (Session["HitCounter"] == null)  
    {
       Session["HitCounter"] = 1;
    }
    else  
    {
       Session["HitCounter"] = ((int) Session["HitCounter"]) + 1;
    }
    return ((int) Session["HitCounter"]);
      }    
--------------------------------
 
The client application code is:WebForm1.aspx.cs
--------------------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Net;
.....
.....
  // Create a new instance of a proxy class for your XML Web service.
      private ServerUsage.Service1 su = new ServerUsage.Service1();
      private CookieContainer cookieJar;
......
  private void Button1_Click(object sender, System.EventArgs e)
      {
       
     
    // Check to see if the cookies have already been saved for this session.
    if (Session["CookieJar"] == null)  
       cookieJar= new CookieContainer();
    else
       cookieJar = (CookieContainer) Session["CookieJar"];
 
    // Assign the CookieContainer to the proxy class.
    su.CookieContainer = cookieJar;
 
    // Invoke an XML Web service method that uses session state and thus
cookies.
    int count = su.SessionHitCounter();    
 
    // Store the cookies received in the session state for future retrieval by
this session.
    Session["CookieJar"] = cookieJar;
 
    // Populate the text box with the results from the call to the XML Web
service method.
    Label1.Text = count.ToString();  
       
 
      }
--------------------------------

I've mono 1.0 installed. 

Where I mistake?

Could anybody help me, please?
 
Thanks a lot,
 
Valentina.