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

狂风中的少年 提交于 2019-11-29 06:58:18

In .NET 4, you can do this in Application_BeginRequest

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

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.

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.

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