Re: Web Service Session Behaviour
- From: "John Saunders [MVP]" <john.saunders at trizetto.com>
- Date: Sat, 16 Jun 2007 12:37:52 -0400
"Mr. Arnold" <MR. Arnold@xxxxxxxxxx> wrote in message
news:eqWdfeBsHHA.1208@xxxxxxxxxxxxxxxxxxxxxxx
"Glenn" <glenn.csharp@xxxxxxxxxxx> wrote in message
news:OaOnr5$rHHA.3484@xxxxxxxxxxxxxxxxxxxxxxx
Hi
I've been experimenting with managing state using the Session object.
I've created a simple WS with a couple of methods, one which sets a
string value, another that retrieves it.
Each method has the WebMethodAttribute.EnableSession set to true.
When I run the test page the session is maintained. However, using a
console application, in between setting the string value and attempting
to retrieve it using the same instance of the client proxy, the value is
lost.
What am I missing?
The fact that it only applies to an ASP.net web browser session I would
think, in your example.
http://msdn2.microsoft.com/en-us/library/system.web.sessionstate.httpsessionstate.aspx
This answer is almost right. ASP.NET session state (even for web services)
is kept in HTTP cookies. A web browser, naturally, knows how to store
cookies and send them back on demand. In order to successfully use a service
that maintains Session state, you need to do the same in your client
programs.
You do this simply by setting the CookieContainer property of your proxy
class instance:
using (MyService service = new MyService())
{
service.CookieContainer = new CookieContainer(); // Other overloads
exist
service.SetSessionValue("string");
string returnedValue = service.GetSessionValue();
if (returnedValue != "string")
{
throw new Exception("Uh-oh!");
}
}
Note that this technique can also be used to set other properties of your
interaction with the web service. See the documentation on the
HttpWebClientProtocol class, especially the Proxy, ClientCertificates,
Timeout, UseDefaultCredentials and Credentials properties.
--
John Saunders [MVP]
.
- Follow-Ups:
- Re: Web Service Session Behaviour
- From: Mr. Arnold
- Re: Web Service Session Behaviour
- References:
- Web Service Session Behaviour
- From: Glenn
- Re: Web Service Session Behaviour
- From: Mr. Arnold
- Web Service Session Behaviour
- Prev by Date: Re: Web Service Session Behaviour
- Next by Date: Re: Web Service Session Behaviour
- Previous by thread: Re: Web Service Session Behaviour
- Next by thread: Re: Web Service Session Behaviour
- Index(es):
Relevant Pages
|