Re: Help understanding sessions in Web service w/ legacy VB6 event handling

Tech-Archive recommends: Fix windows errors by optimizing your registry



On Sep 11, 1:31 pm, "John Saunders [MVP]" <john.saunders at
trizetto.com> wrote:
"Mr. Land" <grafton...@xxxxxxxxx> wrote in message

news:1189528398.350259.12590@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Sep 10, 2:35 pm, "John Saunders [MVP]" <john.saunders at



trizetto.com> wrote:
"Mr. Land" <grafton...@xxxxxxxxx> wrote in message

news:1189447347.560311.280730@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Hello,

I'm seeing some behavior I don't quite understand with the following,
wondering if anyone could shed some light.

We have a legacy VB6 library which reads/writes to a SQL database and
applies rules to transactions. If any rules "fire", notification
needs to be sent to the caller. I'm trying to expose selected
functionalities of this library as Web services.

I have a single Web service class (in VB.NET) which makes calls into
the library. Due to the nature of the functionalities, it is very
desirable to maintain some context between service requests made by
the same user (even though I'm aware that in general this is a no-no),
so I have included the EnableSession:=True attribute in the Web method
definitions.

The wrapped VB6 lib needs to "fire" rules occasionally, back to its
client, and it has been written to use the VB6 Event mechanism to do
this.

The receiving event handlers are implemented as private members of the
Web service class (not themselves exposed as Web services.) When
events are sent from the VB6 library, these handlers update an
ArrayList declared as a member of the Web service class. The Web
methods then have access to the rule firing history.

Here's the behavior I'm trying to understand: there are two Web
methods (call them A and B) in the Web service class that will cause
the rule events to fire. Both are marked with the "enable session"
attribute. When A is invoked, I can step through the various event
handlers with a debugger and see them update the ArrayList. Setting
breakpoints both in A and in the handlers, I can see a valid session
object associated with the containing class. When A is about to
return, the rule results have been accumulated in the ArrayList
member, as I expected.

However, if I then invoke B, although the Web service object seems to
contain the same session when the code of B begins to execute, when
the rule event handlers are subsequently invoked, within the code of
each the session member of the Web service class is now Nothing.
After all the event handlers have processed all the fired events, and
control returns to the Web method B, the ArrayList does not contain
the rule output it should. It's almost as if for some reason when the
rules fire in response to the code in B, a separate instance of the
Web service class is being created only in the context of the VB event
handlers.

How are you storing these members you want to preserve between calls? You
didn't say in your post.
--
---------------------------------------------------------------------------­­-----
John Saunders | MVP - Windows Server System - Connected System Developer

Perhaps I'm misunderstanding what "EnableSession:=True" does, because
I thought I had
in fact described the full scenario.

The data I want to survive across calls to the Web methods of my class
are elements of the
class. I was under the (mis?)understanding that marking one or more
methods of this class
with EnableSession would cause instances of the class to hang around
between calls to its
Web methods, one per unique session. Is that not correct?
-----------------

NO!

EnableSession = true enables the use of ASP.NET Session State, nothing more!
Nothing in the world will keep instance members hanging around when the
instance is deleted!

The best you can do is persist those members you need to persist in Session
state or some other such store. I suggest you factor all such members out
into a separate class, possibly a nested class. Then you just have to think
about persisting the values in the separate class.
--
---------------------------------------------------------------------------­-----
John Saunders | MVP - Windows Server System - Connected System Developer

I tried using the Session, and it didn't work.

What needs to happen is that I need to accumulate the output of all
the calls to the "event handlers"
associated with the legacy VB6 library and use that accumulation to
build the response from the Web
methods.

Here are the stepsI used and the behavior:

1. Web method A is called: method A creates an empty ArrayList and
stores it in the Session.
2. Code in A then calls into VB6 library.
3. During the call, the VB6 library repeatly calls the callback
methods (which are
declared as members of the class implementing the Web Service, ie the
class A belongs to.)
4. Each callback (Event handler) fetches a ref to the ArrayList out of
the Session,
then adds a string to it.
5. After the last event handler executes, method A resumes and fetchs
the
ArrayList out of the Session. It reformats all the strings into its
return value.
(SO FAR SO GOOD)
6. Web Method B is later called. It fetches the ArrayList out of the
Session (which
still has all the strings added from the previous call to A, I checked
this.) It empties
it. (As a test I changed this to add one string: "Hello World")
7. The code in B makes its calls into the VB6 library, just like A did
before.
8. During the call, same thing as before happens: the VB6 library
repeatedly calls
the (same) event handlers.
(HERE IS THE PUZZLER)
9. When each handler now attempts to get the ArrayList out of the
Session, it
gets nothing (and just returns). If I breakpoint here, the Session
member of "Me"
is Nothing (!) It seems there suddenly is no Session.
10. When method B resumes, it still has the Session it started with
(my test: the
same ArrayList is in there with one string: "Hello World".

While stepping through this code, I made note of the session GUID
during the times
I could see a valid Session - they were always the same. During the
execution
of the event handlers invoked by the VB6 lib during B's invocation,
the Session object was Nothing.


For some reason, the event handlers invoked during the execution of B
have no
Session object, but the same handlers DO have a Session object if A is
invoked.
Both A and B are labeled with the "EnableSession" attribute.

Thanks very much for the help.

.



Relevant Pages

  • Re: Help understanding sessions in Web service w/ legacy VB6 event handling
    ... ArrayList declared as a member of the Web service class. ... Both are marked with the "enable session" ... After all the event handlers have processed all the fired events, ...
    (microsoft.public.dotnet.framework.webservices)
  • Re: How do Large Scale Web Service Applications Maintain Session State?
    ... cache these profiles on the server in order to increase performance. ... which is something different than stateful Web Service classes. ... We do pass a session token as ... Having systems deployed through web services allows clients to access via ...
    (microsoft.public.dotnet.framework.webservices)
  • Re: Web Service State
    ... You can enable the ASP.NET session for the web services, but as you said, it ... users store the session state. ... - Store state on the server and uniquely identify each visitor. ... We use windows authentication to authorise users to our web service, ...
    (microsoft.public.dotnet.framework.webservices)
  • RE: Asynchronous Web Service Method Failure
    ... >When a session begins, I create a folder for that session in a virtual ... To open a stream, I use ... >the URL of the file is returned by the web service method. ...
    (microsoft.public.dotnet.framework.aspnet.webservices)
  • RE: Asynchronous Web Service Method Failure
    ... When a session begins, I create a folder for that session in a virtual ... When the user requests a report, sometimes a stream is opened to load some ... the URL of the file is returned by the web service method. ...
    (microsoft.public.dotnet.framework.aspnet.webservices)