3

I have a .NET webservice which I need to hit asynchronously from the jQuery and update the grid based on the result got from service. My problem here is that, the service hit is async only for the first time and the subsequent requests are sync (even after specifying async=true in the ajax call) as shown below

jQuery.ajax({
            type: "POST",
            url: url,
            data: data,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            async: true,
            success: function(msg) {
                var result = msg.d;
                return callback(result);
            },
            error: $.callDotNetSM.onError
        });

My .NET service method is something like below.

[WebMethod(EnableSession = true)]
public static string GetData()
{
}

So, please help me in calling the service asynchronously all the times. Any help is highly appreciated.

1 Answer 1

6

The page your WebMethod is being called on needs to have the following in the Page Directive:

<%@ Page Async="true" EnableSessionState="False" %>

The reason for this is that ASP.NET locks the Session every time it is accessed so that it cannot run asynchronously. Even if you do not use the Session in your WebMethod the page still thinks it uses it by default unless you tell it otherwise.

Edit:

Your problem could also be that you have EnableSession="true". You may just need to set it to false.

Sign up to request clarification or add additional context in comments.

2 Comments

Exactly, my problem was mainly due to EnableSession="true" and not using EnableSessionState="False" in the page directive. Thanks a lot for the help "jmein"!!
Your welcome! So all you needed to do was EnableSession="false" on the WebMethod? I did not know you could do it on a WebMethod by WebMethod basis. I guess I learned something new too. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.