I have some code from the long-ago-left engineer.
It’s generally a call from js to ASP.NET webservice.
The core lines of js was:
var url1="WebService.asmx";
xmlhttp.open("POST", url1, false);
xmlhttp.setRequestHeader("Content-Type","text/xml;charset=gb2312");
var url2="http://mysite.com/save";
xmlhttp.setRequestHeader("SOAPAction", url2);
xmlhttp.send(data);
var result;
var resultTxt;
result = xmlhttp.status;
returnTxt = xmlhttp.responseText;
xmlhttp = null;
if(result==200) {
if(returnTxt.indexOf("save succeeded")>-1)
return "succeeded"
}
return "failed";
The core lines of webservice was:
using (SqlConnection conn = new SqlConnection(connectionString))
{
SqlCommand cmd = new SqlCommand(sqlSelectString, conn);
IAsyncResult ASynResult;
SqlDataReader dr;
try
{
conn.Open();
ASynResult = cmd.BeginExecuteReader(CommandBehavior.CloseConnection);
while (!ASynResult.IsCompleted)
{
ASynResult.AsyncWaitHandle.WaitOne(3000, true);
}
dr = cmd.EndExecuteReader(ASynResult);
value = "save succeeded!!";
}
catch
{
value = "save failed!!";
}
}
My question is:
1 Whether this is Asynchronous or Synchronous?
2 Why use IAsyncResult in webservice?
Its using an asynchronous command, but waiting so in effect its synchronous. I’m not sure what the original intent was. There are valid reason to have web services utilize the IAsyncReqult pattern having to do with using up threads that IIS needs, but that’s not the way to do it. I’m not sure if its an issue with the current version of IIS either. Here is an old link to some info on it, but there may be more present information out there.