How to force an IIS hosted WCF or ASMX [webservice] to use session object readonly?

自作多情 提交于 2019-11-28 00:43:53

问题


While making my first ajax attempts, I decided also, to go to use IIS hosted WCF now. The strange thing is, that the WCF cannot process several requests parallel for the same user/session, if sessionmode is enabled! If sessionmode is disabled on asp.net, the requests are processed parallel. The broser/client may execute several different requests, where some of them are long running. This blocks all further requets and make my ajax app unusable.

This applies to asmx [webservices] also. I had a big hope, to compile the webservice methods using "IReadOnlySessionState" interface, but this has - in oppsite to webpages - no influence. But I need access [most times readonly] to the asp.net session!

Does someone knows any solution to this problems.

Anyway, thanks a lot!

br--mabra


回答1:


In .NET 4, you can do this in Application_BeginRequest

if (Context.Request.Path.EndsWith("xxx.svc"))
   Context.SetSessionStateBehavior(SessionStateBehavior.ReadOnly);



回答2:


I found this:

http://blogs.msdn.com/silverlightws/archive/2009/09/30/having-a-pollingduplex-service-and-any-other-wcf-service-in-the-same-website-causes-silverlight-calls-to-be-slow.aspx

Which states,

"All WCF services require read/write session state access if you enable ASP.Net sessions, which causes the replies to be queued sequentially. Ideally user should be able configure the WCF handler to be read only, which would allow polling duplex services to work with sessions. Unfortunately this is unsupported at this point."

...the only thing I can think of is if there's some way to manually force early release of the lock. I'm looking into that now.




回答3:


You can provide a custom session state provider

See: http://koolsand.blogspot.com/2010/02/why-iis-hosted-wcf-services-does-not.html

whenever a request contains svc in the path it intimates default session state provider to use readonly lock and not read-write lock. So using readonly lock will allow the next wcf call to be executed concurrently.



来源:https://stackoverflow.com/questions/1269198/how-to-force-an-iis-hosted-wcf-or-asmx-webservice-to-use-session-object-readon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!