Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
169 views
in Technique[技术] by (71.8m points)

asp.net - Trying to make Web Method Asynchronous

The project I am currently working on involves MS SQL Server and ASP.net Web Services that use Session variables. Apparently this causes a client's calls to execute in a sequential manner. I want to make sure that these methods execute asynchronously.

After doing some research it appears to me the choicest method is to persist the session state in the database using a table that tracks sessions ( using guids say ) and separate tables for each session.

Before I dive directly into this I need to know if I can gain the same sense of asynchronous operations for the web service if I configure SQL Server to store the session.

Can I ?

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Sorry to say that, but the only way to execute asynchronously your code and use session variables is to make your totally custom session solution - and I mean totally custom and disable the asp.net session entirely.

Basic tips to make your session:

  1. You have one cookie connected with the users data
  2. The data is on one table on your database.
  3. You make custom fields on that table for each session and avoid Dictionary<> to keep them
  4. You work with Dirty read, last write wins
  5. You read and write only the session variables that you need each time (not all together)
  6. Each line have a time out date, and use like MS, a sheduler on SQL to delete old sessions.
  7. Load session on OnPreInit, save only what have change on OnUnload
  8. By entirely disable the session, you need to lock using Mutex code that now is work fine because the session is make synchronization with out notice it, but with out session lock maybe execute two times, like new inserting to database calls.

relative:

Web app blocked while processing another web app on sharing same session
What perfmon counters are useful for identifying ASP.NET bottlenecks?
Replacing ASP.Net's session entirely

to answer and to this question if I configure SQL Server to store the session ? the session is still lock and block the rest request. If you have the session on SQL server or on other medium is not change the way of working, only the place of the saved data.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...