Re: Web Service Session Behaviour

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



"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]


.



Relevant Pages

  • Weird PropertyBag problem, values wont change
    ... CSession - Data storage class for a session. ... CSessions - Collection of CSession objects for all logged in users. ... Public Property Let ID(ByVal vData As String) ... Public Sub Remove ...
    (microsoft.public.vb.controls)
  • server-side JavaScript: Prototypes of built-in classes, objects and functins
    ... Session object (disk-based session variables for data persistence ... File class (manipulation of files on server, ie. open, close, read, ... //Methods Cgi.queryCgi.postCgi.anyby default return an empty string if requested var not found ...
    (comp.lang.javascript)
  • Calling a public function to email a report
    ... Public Sub SendNotesMail(Subject As String, Attachment As String, ... Dim UserName As String 'The current users notes name ... Dim Session As Object 'The notes session ... Set Maildb = Session.GETDATABASE ...
    (microsoft.public.access.modulesdaovba)
  • RE: Sending Lotus Notes Mail from Access - Bypassing Password
    ... > I think you can use the currently logged in session of Notes, ... >> Code:Public Sub SendNotesMail(Subject As String, Attachment As String, ... >> Dim UserName As String 'The current users notes name ... >> Dim MailDbName As String 'THe current users notes mail database name ...
    (microsoft.public.vb.general.discussion)
  • Re: Repeater paging problem
    ... First about your "authentication". ... The way things should be done: Create checkboxes inside ... your comma separated string property will already be ready when your ... Doing it this way, you won't need no Session variable, no iteration thru ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)