views:

35

answers:

2

Hi,

I'm making a .net component, resulting in a dll assembly, that will be referenced by an asp.net site, and in another project by an asmx webservice. All code is version 2.0.

The component has a few functions that call an external webservice, which returns an object. One of these functions is for example Login(username, password), which generates amongst others a unique session id for this user. The resulting information and session id are stored in variables in the component.

The issue in the website is: When the user logs in in the frontend, and my component gets called and checks the login and generates the session id, I want that information in my component to persist when the user browses to another page in the site.

The issue in the web service using my component is: I don't really care much about session state, but I want the component to just work. If per call a new session id is generated, that's okay.

The combination of the two environments causes the following problem for me:

  • I can't use the asp.net Session() variable in my component without referencing system.web, which is kinda silly and might not be available in the web service project that includes my component
  • I can't program my component as a singleton, because then in the website application, it's shared amongst all visitors, overwriting sessions and whatnot
  • making an array of "session information" in my component and maintaining that is hard to program (when does it get invalidated?) and might not work in a web farm environment

Is there a solution to this situation? Or should I make two instances of my component, one for use in websites, and one for use in web services?

+1  A: 

Perhaps I'm not understanding what your asking but why can't you do something like:

Component.Login(user,pass);
Session["Component"] = Component.SessionID
cptScarlet
Because there are unfortunately more variables than just sessionid, and also because using this principle, i'm asking that the programmer using my component has to make sure he does the session storage part as well (instead of just using its methods and relying on it just working). If my component itself would take care of the storage, it'd be easier. Maybe i'm trying to oversimplify for the other party?
Tominator
What else are you keeping track of?
cptScarlet
A larger object with multiple arrays of values and whatnot. Kinda hard to explain what exactly, just a whole bunch of data.. But i've decided that the user can pass in a session reference if he wants, and with that the object gets saved. If he passes nothing, it doesn't get saved. Best of both worlds i guess..
Tominator
+1  A: 

I've created an extra class "Factory" which has a .Create(byref Session as HttpSessionState), that looks if the passed in session object is Nothing, if not, it checks if there is a Component object in it, if so, it uses it, if not, it creates it and adds it to the session.

In the case of the webservice call, the factory gets the Nothing-parameter, so it doesn't check in the session object. It seems to work.

Thanks for your answers!

Tominator