I have a client/service.
The service has a method that takes a long time to do (it interacts with a database).
I’m call this method via a AJAX request from the page to the client, then to the service and back.
My service code:
[WebMethod]
public static string LookupUPC(string sessionId, string upc) {
string response = "";
var client = new SmartShopService.SmartShopInterfaceClient();
try {
response = client.LookupUPC(sessionId, upc);
}
catch (Exception e) {
throw e;
}
finally {
if (client.State == System.ServiceModel.CommunicationState.Faulted)
client.Abort();
else
client.Close();
}
return response;
}
It is called from the page by an AJAX request
for(var i = 0;i<10; i++){
$.ajax({
type: "POST",
url: "SmartShopGUI.aspx/LookupUPC",
contentType: "application/json; charset=utf-8",
data: DataCreator(allData),
dataType: "json",
success: function (result) {
$(upcName).html(result.d);
},
error: AjaxFailed
});
}
Now, this is done asynchronously on the page, but the client is sending the requests synchronously. I want to change it so that if it asks for 10 all at once, it’ll send 10 different requests to the service.
http://www.screencast-o-matic.com/watch/cX1Qo8qV2
Here is a video that might help.
Remove the reliance on Session in the webmethod, you’ll probably find that session access is serial and that is what the block is.
http://msdn.microsoft.com/en-us/library/ms178581.aspx