473,385 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

WCF PerCall instance State Aware

Hi,

I am in the process of converting an Oracle forms application to Asp.Net. Currently I am using a WCF web service to manage all of my Oracle database calls and to convert the data in to business objects. The business objects can then be easily consumed by the Asp.Net application. All of this works fine.

The problem I am having is with performance on the service. Since my instancing mode is per call the webservice needs to recreate the state/security object on every call. The state object includes a database connection, security parameters, and various other values that are required to set the users context.

Based on what I have read the best way to accomplish this is to store the state objects in memory/static variable and to provide some sort of reference to the client that it can use on each service call. I understand that memory is volatile and can be recycled for various reasons in IIS, this is fine since the data in question is not important and can be regenerated. The objects to be stored are not that large, but they are created from several complex queries, and doing this on each service call is very expensive.

Can someone give me some code examples of the best method of storing this data in memory on the web service?

Thanks
Nov 15 '09 #1

✓ answered by cloud255

Have a look at the singleton approach and inversion of control this is useful when creating and managing services. A user state service might be the solution to your problem.

Also check to see if your list/dictionary is being garbage collected, have a look at the KeepAlive method of the garbage collector. You may use this method to prevent the garbage collector from removing a reference from memory. Remember that if you have no references to a variable the garbage collector will dispose of the object.

P.S. If your problem persists, post the code which you use to read and add data to your list and we'll have a look at it.

3 4005
cloud255
427 Expert 256MB
What I usually do is create a server side cache to store these instances. Upon authentication I send a unique ID back to the client machine, this ID is then used upon each request to the server. Note that this ID should be more complex than just an integer for security reasons. A hash value or some sort of randomly generated string works well.

User data is stored in a dictionary which the server uses for lookups, the unique ID being the key of the dictionary. The issues with this approach is that you need to build in some sort of timeout mechanism, which invalidates the ID on the server side and removes the entry from the dictionary, thus freeing memory. A simple way to do this is to add a time stamp to the dataobject held by the dictionary, this time stamp represents the last time the client sent a request to the server. I then have a thread which runs every x minutes checking the time span from the last last client activity and removes all expired entries.

On another note the database connection information is generally stored in a data access layer which is independent of the state/security objects. The data access layer has several exposed methods allowing clients to access data and stored procedures. This allows one to only pass an enumeration to said method representing the user's authority level. The function can then internally check if the user has rights to execute it. This approach works well when you define several user roles within the system with respects to access privileges.

Hope this helps

P.S. What I described above is how I code our client/server application, things may vary slightly in a web based environment. My knowledge of web programming is not nearly enough to be sure which aspects may differ.
Nov 16 '09 #2
Initially I had designed the data access layer to be completely seperate from the business services. The issue I am facing is that since it is currently an Oracle forms application, all of the application login accounts are actually Oracle database accounts and their permissions are managed by the builtin roles table. I need both applications to continue working concurrently until the new application has been completed. So what I have done as a work around is added the db connection to the state object which it can pass in to the data access layer.

Anyway going back to the original issue, thanks for your reply it has reassured me on alot of things. I think I am headed in the right direction now. I am still a bit confused as to how to actually code in this static dictionairy to contain all of the state objects. In my most recent attempt I created a static class with static list and it stills seems to be cleared/recycled quite frequently. I can never get more than 10 objects into the list before it is cleared and even when I try to retrieve information back it is never valid. I verified my IIS settings are set to recycle once a day at 3am.

I believe it has something to do with my instancing mode being per call, although I am not experienced enough with WCF to know for sure. Are there any special workarounds I need to implement so that I can persist static variables for the lifetime of the application?

Thanks
Nov 16 '09 #3
cloud255
427 Expert 256MB
Have a look at the singleton approach and inversion of control this is useful when creating and managing services. A user state service might be the solution to your problem.

Also check to see if your list/dictionary is being garbage collected, have a look at the KeepAlive method of the garbage collector. You may use this method to prevent the garbage collector from removing a reference from memory. Remember that if you have no references to a variable the garbage collector will dispose of the object.

P.S. If your problem persists, post the code which you use to read and add data to your list and we'll have a look at it.
Nov 16 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Lee Harr | last post by:
Is there an easy way to sort the stats returned from the hotshot.Profile() by the percall column?
2
by: Edward Diener | last post by:
Is there a way in Python to have the constructor of a class "return" another instance of the same class ? I am well aware of the fact that __init__ does not return anything, but I would love to do...
8
by: Matthew Bell | last post by:
Hi, I've got a question about whether there are any issues with directly calling attributes and/or methods of a threaded class instance. I wonder if someone could give me some advice on this. ...
6
by: Martin | last post by:
I'd like to be able to get the name of an object instance from within a call to a method of that same object. Is this at all possible? The example below works by passing in the name of the object...
18
by: Steve Barnett | last post by:
I want to ensure that there is only ever one instance of my app running on a single PC at any time. I understand that I can achieve this by using a mutex and, if I can't take ownership of the...
3
by: Adam | last post by:
We have a web site that uses .vb for the web pages and .cs for a class module. We are getting the error in .NET 2.0 and VS 2005 beta 2. It does work with .NET 1.1. When trying to access a page...
6
by: spacehopper_man | last post by:
I'm considering ditching all use of Session state in favour of Application state. This is because - from what I can work out - it will be more memory efficient for me. I have three questions:...
22
by: WXS | last post by:
Sometimes a method in a class requires the use of class instance variables/fields that will not be used outside of the method itself. Currently this means you must create a instance field in the...
7
by: dmitrey | last post by:
hi all, Is there a better way to kill threading.Thread (running) instance than this one http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496960 (it's all I have found via google). BTW,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.