Hi Everyone,
Most tutorials I've seen address cookies from the server's perspective,
assuming that the client (usually a browser like Internet Explorer)
will manage the persistence. I am faced with writing a C#.NET client
that uses a web reference to a SOAP web service, and I need to persist
the cookies myself, or so it seems. The cookies stored in temporary
internet files - accessed each time I hit the web service help page
from IE during testing - don't appear to have any relationship with the
cookies that will be used by my homemade client. Is this correct, or am
I doing something silly? I'd really appreciate a code snippet if
possible.
Thanks,
Jono 5 13772
Sounds like a job for the CookieContainer object:
HttpWebClientPr otocol.CookieCo ntainer Property http://msdn2.microsoft.com/en-us/lib...container.aspx
CookieContainer Class http://msdn2.microsoft.com/en-us/lib...container.aspx
--
Chris Fulstow
MCP, MCTS http://chrisfulstow.blogspot.com/
Jono wrote:
Hi Everyone,
Most tutorials I've seen address cookies from the server's perspective,
assuming that the client (usually a browser like Internet Explorer)
will manage the persistence. I am faced with writing a C#.NET client
that uses a web reference to a SOAP web service, and I need to persist
the cookies myself, or so it seems. The cookies stored in temporary
internet files - accessed each time I hit the web service help page
from IE during testing - don't appear to have any relationship with the
cookies that will be used by my homemade client. Is this correct, or am
I doing something silly? I'd really appreciate a code snippet if
possible.
Thanks,
Jono
Hi,
Jono wrote:
Hi Everyone,
Most tutorials I've seen address cookies from the server's perspective,
assuming that the client (usually a browser like Internet Explorer)
will manage the persistence. I am faced with writing a C#.NET client
that uses a web reference to a SOAP web service, and I need to persist
the cookies myself, or so it seems. The cookies stored in temporary
internet files - accessed each time I hit the web service help page
from IE during testing - don't appear to have any relationship with the
cookies that will be used by my homemade client. Is this correct, or am
I doing something silly? I'd really appreciate a code snippet if
possible.
Thanks,
Jono
I wrote about that referring to WPF, but it's the same for WinForms. http://geekswithblogs.net/lbugnion/a.../11/93743.aspx
HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
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
Laurent Bugnion wrote:
Hi,
Jono wrote:
Hi Everyone,
Most tutorials I've seen address cookies from the server's perspective,
assuming that the client (usually a browser like Internet Explorer)
will manage the persistence. I am faced with writing a C#.NET client
that uses a web reference to a SOAP web service, and I need to persist
the cookies myself, or so it seems. The cookies stored in temporary
internet files - accessed each time I hit the web service help page
from IE during testing - don't appear to have any relationship with the
cookies that will be used by my homemade client. Is this correct, or am
I doing something silly? I'd really appreciate a code snippet if
possible.
Thanks,
Jono
I wrote about that referring to WPF, but it's the same for WinForms. http://geekswithblogs.net/lbugnion/a.../11/93743.aspx
HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
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 GetSessionIdSer vice.Service1 m_oService
= new GetSessionIdSer vice.Service1() ;
public Page1()
{
InitializeCompo nent();
m_oService.Cook ieContainer = new System.Net.Cook ieContainer();
}
}
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 "CookieContaine r" 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
Thanks Laurent,
I will give it a try!
Regards,
Jono
Laurent Bugnion wrote:
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 GetSessionIdSer vice.Service1 m_oService
= new GetSessionIdSer vice.Service1() ;
public Page1()
{
InitializeCompo nent();
m_oService.Cook ieContainer = new System.Net.Cook ieContainer();
}
}
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 "CookieContaine r" 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Blossom |
last post by:
Hi there,
I have a problem with storing my Cookies. I made a servlet in which I
store a Cookie (in the doGet()-method) to detect whether a user has
already visited my webpage.
I used the following code:
Cookie c = new Cookie("sessionID", generateSessionID());
c.setMaxAge(60*60*24*365);
|
by: Brian Burgess |
last post by:
Hi all,
Anyone know of any special issues with storing cookies with ASP? I'm
trying this with two browsers: One is IE 6.0 with cookies set to
'prompt'. This has been working properly as any new site I goto seems
to prompt me to store their cookie. The other is Pocket IE on Pocket
PC 2002, with the cookies set to 'enabled'.
My...
|
by: Rob Meade |
last post by:
Hi all,
At work we have 2 servers in a cluster for our web apps.
One problem we have experienced (along with many others!) - is that if a
user is logged into one of the applications on server a for example and it
goes offline or fails their session is lost also - even though the
application becomes available on server b.
I have heard...
|
by: Robert Hanson |
last post by:
I am new to the asp.net application building and I have read the
information regarding the storing of information using session vs
cookies vs viewstate. I am asking for suggestions/guidance as to when
each is appropriate. I noticed that in the case of cookies, there is a
liability because of web browser settings migh disallow the storing of...
|
by: TahseenTarafdar |
last post by:
Hi,
I am updating a Java servlet to store cookies. The class inherits from HttpServlet and overrides the "service" method. Within this method I have the following code to test cookie storing and retreival:
public void service( HttpServletRequest req, HttpServletResponse res ) throws IOException
{
......
Cookie cookies =...
| |
by: Mike |
last post by:
I have developed an application, for psyc patients.... they type in
very personal information in a web form to help them work through
problems in their lives. Once they enter the info, I encrypt the data
and store it in a MySQL database. Users can then print, edit, delete
or share the information they entered with their therapist. I'm not...
|
by: Milsnips |
last post by:
Hi there,
i had a small project where i used a session to store the shopping cart, but
if it times out, the user loses the cart.
Then i thought instead of using session, i'll store the cart in a cookie,
but cookie only stores string values, which makes it tricky to update/remove
cart item values because i'd have to so substring, split,...
|
by: Miesha.James |
last post by:
Hello,
I'm trying to rewrite visual c++ code into visual c++ .NET code and
I've run across a problem with storing objects into a list.
Here;s an example of the code I have:
ref struct Cookies
{
String^ Name;
|
by: sarvesharnie |
last post by:
dear folks,
i developed a small web browser... on that web browser i need to store the cookies and retrieve the cookies... how to do that .
i developed this application C# windows application... please help me out.
regards
sarvesh
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |