Cookies and web services

  • Thread starter Laurent Bugnion
  • Start date
L

Laurent Bugnion

I posted this in the WinForms forum, and didn't get an answer yet. Come
to think of it, I am sure some of you guys were confronted to that
problem too, because the same scenario can happen in ASP.NET too
(server-side of course). Allow me to post here too:

Hi,

I got a problem when I try to connect to a stateful web service using a
Windows Forms application (actually, a WPF application, but it's the same).

Simplified code:

SERVER:

[WebService( Namespace = "http://www.galasoft-lb.ch/" )]
[WebServiceBinding( ConformsTo = WsiProfiles.BasicProfile1_1 )]
[ToolboxItem( false )]
public class Service1 : System.Web.Services.WebService
{
[WebMethod( EnableSession=true )]
public string GetSessionId()
{
return Session.SessionID;
}
}

CLIENT:

private Service1 m_oService = new Service1();

public Form1()
{
InitializeComponent();
m_oService.CookieContainer = new CookieContainer();
}

private void bnExecute_Click( object sender, EventArgs e )
{
try
{
DisplayResults( m_oService.GetSessionId(), false );
}
catch ( Exception ex )
{
DisplayResults( ex.Message, true );
}
}

Any idea what's causing the problem? The cookies are never set.

Thanks,
Laurent
 
J

John Timney \(MVP\)

Hi Laurent,

Try moving the declaration of cookiecontainer into the private declarations
of your client

private Service1 m_oService = new Service1();
private CookieContainer myCookies = new CookieContainer();

and set that


public Form1()
{
InitializeComponent();
m_oService.CookieContainer = myCookies;
}





--
--
Regards

John Timney (MVP)
VISIT MY WEBSITE:
http://www.johntimney.com
 
L

Laurent Bugnion

Hi John,
Hi Laurent,

Try moving the declaration of cookiecontainer into the private declarations
of your client

private Service1 m_oService = new Service1();
private CookieContainer myCookies = new CookieContainer();

and set that


public Form1()
{
InitializeComponent();
m_oService.CookieContainer = myCookies;
}

Thanks for your reply. Actually, my client-side code was fine. Funnily
enough, after a looooong time spent looking for the error, I finally
(with the help of a colleague) found out what the problem was, and it
was in the server: When I created the Web service application, the
Global.asax handler was missing. This is the new default in ASP.NET 2.0
(in 1.1, the Global.asax was always present by default).

When the Global.asax is missing, the application runs fine, but without
any session management. Everything occurs as if a new Session started on
every request.

Actually, you can try deleting the Global.asax in a 1.1 Web service
application, and the same result can be observed: The SessionID is
different on every request.

Anyway, thanks for taking the time.

Greetings,
Laurent
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top