11

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?

Mike Cole
  • 14,474
  • 28
  • 114
  • 194
Tuviah
  • 723
  • 2
  • 10
  • 20

1 Answers1

6

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.

Community
  • 1
  • 1
Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
  • Actually IE 8. Safari and FireFox can execute more than 2 requests to the same server. I believe IE 8 is 6. And yes I confirmed from another machine. – Tuviah Feb 16 '11 at 23:53
  • in regards to turning session state off is not an option. I use session other places to count concurrent users. Why is it that ASMX web services have the ability to turn on and off session state per method and WCF services do not. – Tuviah Feb 16 '11 at 23:54
  • @Tuviah: Unless you have full control over browsers used by your clients you should still count with two parallel requests. For example I'm working in company with 10k computers where IE6 is standard and we are moving to IE7 ... (yes that's an upgrade, lol). – Ladislav Mrnka Feb 17 '11 at 09:34
  • @Tuviah: Btw. are you sure that your service calls participate in ASP.NET session? How is your service endpoint configured? – Ladislav Mrnka Feb 17 '11 at 09:35
  • my service calls don't participate in using session. I wrote only one service method which simply sleeps for 20 seconds and returns a number. – Tuviah Feb 17 '11 at 15:32
  • Landislav even if it was two parallel requests I should see two requests returning at roughly the same time. I just see one after the other with 20 seconds between each. – Tuviah Feb 17 '11 at 15:34
  • service end point is configured with Factory="System.ServiceModel.Activation.WebServiceHostFactory" in svc file. and nothing else is in the .config except turning on aspnetcompatibility enabled/ – Tuviah Feb 17 '11 at 15:35