Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AspNetCompatibilityRequirements causes WCF web service to block [duplicate]

Tags:

asp.net

wcf

Hello I have a simple wcf service like this, with a test method which simply sleeps for 20 seconds and returns a value. I wrote a test page which uses jquery to call it 10 times in a row, and it appears to execute concurrently, with the client waiting 20 seconds and then getting results back from all of the services at about the same time.

 [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall,ConcurrencyMode=ConcurrencyMode.Multiple,UseSynchronizationContext=false)]
public class AjaxTestWCFService : IAjaxTestWCFService

However if I set

aspNetCompatibilityEnabled="true"

in web.config then no matter what I do, with concurrencymode, usesynchronizationcontext or instance context mode, or even serviceThrottling config, it appears to execute each web service call sequentially, with it taking 2 minutes for all 10 requests to return!!

Now I realize that this may be because of session, but at least in ASMX services I was able to set enablesession to false. And in fact my web service method is not using session at all. So you may wonder, why use aspNetCompatibilityEnabled at all. Because I want to use ASP.net impersonation and forms authentication.

I even set

[ServiceContract(SessionMode=SessionMode.NotAllowed)]

So my question is, is this by design and how can I enable concurrent web service requests with ASP.net compatibility enabled?

like image 474
Tuviah Avatar asked Feb 16 '11 17:02

Tuviah


1 Answers

This is by design of ASP.NET itself - check concurrent requests and session state. Once you turn on AspNetCompatibilityEnabled you always have to deal with that - I didn't try it but I expect that the only option can be turning off the session in configuration file.

<configuration>
  <system.web>
    <sessionState mode="Off" />
  </system.web>
</configuration>  

But still your test is probably not very realistic. When AspNetCompatibilityEnabled is turned off it will execute in parallel localy but I expect that if you run the page from different computer you will not be able to execute more then two requests in parallel. The reason is that by default HTTP persistent connection is used. By HTTP specification only 2 HTTP persistent connections can be opened to the same server = only two parallel requests can be executed (last paragraph before chapter 8.2). Windows follow these recommendations.

Edit:

This thread on MSDN forum disusses the same issue. It also provides some solution.

like image 132
Ladislav Mrnka Avatar answered Nov 07 '22 07:11

Ladislav Mrnka