[Mono-list] Troubles with Session in Web Services, client side

Juan Cristóbal Olivares juancri at gmail.com
Wed Dec 27 22:52:11 EST 2006


You should do something like this:

// Create session counter
SessionCounter stub = new SessionCounter();

// Crearte the cookiecontainer
CookieContainer cookies = new CookieContainer ();

// Asign it
stub.CookieContainer = cookies;

// Increment
for (int i = 0; i < 15; i++)
        stub.Increment ();


Hope this helps... best regards.

Juan C. Olivares
www.juancri.com

On 12/26/06, Sébastien Mosser <mosser at polytech.unice.fr> wrote:
>
> Hi everybody.
>
> I got a problem while trying to invoke a WS written in C#. the WS is
> quite simple, and is just a sample of 'How to use Session in .Net Web
> Services : A Simple Session Counter'.
>
> The Web User interface works fine (counter value changes well), but,
> when I invoke it from a C# client, it doesn't :'(
>
> The following problem happend on my iBook (Mac OS X, Mono 1.2.1) and
> on my desktop (Kubuntu, mono 1.1.13.6), even using xsp or xsp2 as Web
> Server, ans mcs or gmcs as compiler ...
>
> WS Source code is the following :
> petitroll at bartimeus:~/Adore/webservices/sandbox/session_counter$ cat
> SessionCounter.asmx
> <%@ WebService Language="C#" Class="
> Adore.WebServices.SandBox.SessionCounter"%>
> /**
> * Test Web Service : Test usage of Session in .Net Web Services !
> * @author Sebastien Mosser
> * @date 2006.12.23
> */
> using System;
> using System.Web.Services;
> using System.Xml.Serialization;
> namespace Adore.WebServices.SandBox
> {
>   [WebService( Namespace="http://rainbow.essi.fr/Adore4ws/",
>                Description="A quite simple service using session") ]
>   public class SessionCounter: System.Web.Services.WebService
>   {
>     public SessionCounter() {}
>     [WebMethod( Description="Reseting the session counter value",
>                 EnableSession=true)]
>     public void ResetValue() { Session["counter"] = 0; }
>     [WebMethod( Description="Increment by one the session counter",
>                 EnableSession=true)]
>     public void Increment() {
>      if (Session["counter"] == null)
>        ResetValue();
>       int i = (int) Session["counter"] ;
>       Session["counter"] = i+1;
>     }
>    [WebMethod( Description="Get the session counter internal value",
>                EnableSession=true)]
>     public int GetValue() {
>      if (Session["counter"] == null)
>        ResetValue();
>      return ((int) Session["counter"] ) ;
>     }
>   }
> }
>
> Client code is :
> petitroll at bartimeus:~/Adore/sandbox/DotNetWSClients/SessionCounter$ cat
> Test.cs
> /** A simple SessionCounter Test
> * @author Sebastien
> */
> using System;
> namespace Adore.WsClient.SessionCounterTest
> {
>   public class Test
>   {
>     public static void Main()
>     {
>       Console.WriteLine("####");
>       Console.WriteLine("## SessionCounter.asmx .Net Client");
>       Console.WriteLine("####");
>       SessionCounter stub = new SessionCounter();
>       Console.WriteLine("## Session Counter Value : " + stub.GetValue());
>       Console.WriteLine("## Incrementing counter 15 times");
>       for (int i = 0; i < 15; i++) {
>         Console.WriteLine("## Invoking 'SessionCounter::Increment()'");
>         stub.Increment();
>       }
>       Console.WriteLine("## Session Counter Value : " + stub.GetValue());
>     }
>   }
> }
>
> Execution provide the following result, which is not ... normal :'( :
>
> petitroll at bartimeus:~/Adore/sandbox/DotNetWSClients/SessionCounter$ make
> run
>
> dowmnloading WSDL contract, generate .Net Stub class
> wsdl "http://localhost:9000/sandbox/session_counter/SessionCounter.asmx"
> Mono Web Services Description Language Utility
> Writing file 'SessionCounter.cs'
> mcs /out:Test.exe /r:System.Web.Services *.cs
> mono Test.exe
> ####
> ## SessionCounter.asmx .Net Client
> ####
> ## Session Counter Value : 0
> ## Incrementing counter 15 times
> ## Invoking 'SessionCounter::Increment()'
> [ ... snipped 13 times ... ]
> ## Invoking 'SessionCounter::Increment()'
> ## Session Counter Value : 0
> petitroll at bartimeus:~/Adore/sandbox/DotNetWSClients/SessionCounter$
>
> does anybody got an idea ? I think I'm missing something obvious ...
>
> Cheers,
>
> --
> Sebastien Mosser
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
>



-- 
Juan Cristóbal Olivares
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-list/attachments/20061228/c8f636a9/attachment.html 


More information about the Mono-list mailing list