Re: Storing Cookies from C#.NET Application

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi,

Jono wrote:
Hi Laurent,
Thanks for your post but unless I misunderstood your blog, I am
approaching the problem from a different perspective. I have no access
to the web service code that runs on the server; all I have to do is
store all the cookies sent by the server and return them on subsequent
requests if they are valid (e.g. they match the server's domain and
path and the cookies haven't expired.) I am thinking of using the
CookieContainer object and serializing it to XML on the file system in
between runs of the client application so that cookies don't expire
prematurely (e.g. a cookie might be set to expire only at the end of
the week but the client application might restart many times before
that).
Regards,
Jono

No, no, this code runs on the client:

public partial class Page1 : Page
{
private GetSessionIdService.Service1 m_oService
= new GetSessionIdService.Service1();

public Page1()
{
InitializeComponent();
m_oService.CookieContainer = new System.Net.CookieContainer();
}
}

You see the instantiation of the web service in my WPF application in your case, it would be in the WinForms "OnInit" method, probably), and then you must create and set the "CookieContainer" property of the web service client.

If no CookieContainer is created, the session cookie sent by the web service will be ignored, and a new session will be started on every call.

HTH.
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
.



Relevant Pages

  • Re: How to mantain the state between 2 call of the same WebService?
    ... > work with a custom class like this example: ... of band contract of using cookies from the client. ... at least in the spirt of the web service ...
    (microsoft.public.dotnet.framework.aspnet.webservices)
  • Re: Storing Cookies from C#.NET Application
    ... store all the cookies sent by the server and return them on subsequent ... between runs of the client application so that cookies don't expire ... that uses a web reference to a SOAP web service, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Storing Cookies from C#.NET Application
    ... to the web service code that runs on the server; all I have to do is ... store all the cookies sent by the server and return them on subsequent ... between runs of the client application so that cookies don't expire ... Laurent Bugnion, GalaSoft ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Windows app using webservice sessions and cookies
    ... I have a custom set of usernames and passwords that I want to pass ... to the web service and have it validate the user before doing ... Should I use cookies? ...
    (microsoft.public.dotnet.framework.aspnet.webservices)
  • Re: Storing Cookies from C#.NET Application
    ... Most tutorials I've seen address cookies from the server's perspective, ... assuming that the client ... will manage the persistence. ... that uses a web reference to a SOAP web service, ...
    (microsoft.public.dotnet.languages.csharp)