I have an ASP.NET (3.5) web page which calls a few web methods (SOAP based) using jQuery's .ajax method. The web methods implement 'ScriptMethod' attribute and return JSON data. The web service file (asmx) is local to the same project.
I noticed these web methods execute synchronously on the server which means they run sequentially and affect performance negatively, some methods are waiting, when some of them are slow.
I read this article and I am not sure if I understand that WebMethods which implement Scriptmethod can run synchronously only (they implement IHttpHandler not IH开发者_运维问答ttpAsyncHandler).
If this is true, I might have to change the design.
I am looking for other designs, maybe like using WCF, where the browser can call webmethods using JavaScript and the web methods run asynchronously on the server.
Any ideas or sample code?
Since you are calling the web service from the browser using the ajax method in jQuery, the call is already asynchronous. You can see this in the $.ajax documentation at http://api.jquery.com/jQuery.ajax/. If you make 3 ajax calls in a row, each will execute at the same time and the callback function will kicked off in first-come first-server basis.
Hopefully I am not misunderstanding your question.
If you are using WCF you can use the service behavior attribute as follows: [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]
http://msdn.microsoft.com/en-us/library/system.servicemodel.servicebehaviorattribute.concurrencymode.aspx
精彩评论