Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I have a requirement in which i have to develop a page which runs a service on server calling through JavaScript. Now i also need to show updates about work being done(e.g Completed %).

Heres structure of my code.
C#
       [WebMethod (true)]
       //Below method takes around 5-10 minutes in execution
       public string[] GenerateXMLSiteMap()
       {
         SiteMapGenerator siteMapGen = new SiteMapGenerator();
         siteMapGen.SiteMapNodeAddedSuccessfully += new               SiteMapNodeAdded(siteMapGen_SiteMapNodeAddedSuccessfully);
           siteMapGen.GenerateSiteMap();

           return GetStats();
       }

void siteMapGen_SiteMapNodeAddedSuccessfully(string[] infos)
       {
           //CurrentPage = infos[0];
           Session["CurrentPage"] = infos[0];
           Session["PageScanned"] = infos[1];
           Session["LinkDepth"] = infos[2];
           Session["Time"] = infos[3];
       }

[WebMethod (true)]
       public string[] GetStats()
       {
           string[] stats = new string[4];
           if (Session["CurrentPage"] != null)
           {
               stats[0] = Session["LinkDepth"].ToString();
               stats[1] = Session["CurrentPage"].ToString();
               stats[2] = Session["PageScanned"].ToString();
               stats[3] = Session["Time"].ToString();
           }

           return stats;
       }


I am calling GetStats() method from clientside but it is never invoked. I figured its because we have called GenerateXMLSiteMap() which is still executing. Can anyone tell me how to get statics in this manner.

Thanks,
Dinesh
Posted

1 solution

If you've just call 2 web methods asynchronously, then that is not a problem.

Can you post your client side code here?
Use a tool like Fiddler to see if you can see a call being invoked and a response being sent back.
 
Share this answer
 
Comments
dinesh_ahuja 6-Aug-11 12:51pm    
$(function () {
callService();
});
function callService() {
sitemap.XMLSiteMapService.set_defaultSucceededCallback(OperationCompleted);
sitemap.XMLSiteMapService.set_defaultFailedCallback(onFailed);
sitemap.XMLSiteMapService.GenerateXMLSiteMap();
doTimer();
}

function OperationCompleted(result) {
var divComp = document.getElementById("divComplete");
divComp.style.visibility = "visible";
SetStats(result);
}

function onFailed() {
}

function GetStats() {
sitemap.XMLSiteMapService.GetStats(StatusSuccess, StatusFail);

}

function StatusSuccess(result) {
SetStats(result);
}

function SetStats(result) {
var currentPage = document.getElementById("lblCurrentPage");
if (currentPage != null) {
currentPage.innerHTML = result[1];
document.getElementById("lblDepth").innerHTML = result[0];
document.getElementById("lblPageScanned").innerHTML = result[2];
document.getElementById("lblTimePassed").innerHTML = result[3];
}
}

function StatusFail() {
}

var c = 0;
var t;
var timer_is_on = 0;
function timedCount() {
t = setTimeout("timedCount()", 15000);
GetStats();
}

function doTimer() {
if (!timer_is_on) {
timer_is_on = 1;
timedCount();
}
}

function stopCount() {
clearTimeout(t);
timer_is_on = 0;
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900