Returning Values From Asynchronous Web Service Call
From: weblogs.asp.net
private static int myMethod() {
myWebservice ws = GetWS();
DateTime StartTime = DateTime.Now;
AsyncCallback cb = new AsyncCallback(thisapp.myMethodCallback);
IAsyncResult ar = ws.BeginWSMethod(cb, ws);
while (ar.IsCompleted == false); // this keeps things cranking so I can get total processing time
Log(StartTime, recs.ToString() + " Records Processed");
return recs; // recs returned to console Main{} block
}private static void myMethodCallback(IAsyncResult ar) {
myWebservice ws = (myWebservice) ar.AsyncState;
recs = ws.EndWSMethod(ar);
}// shared webservice configuration method
private static myWebservice GetWS() {
myWebservice ws = new myWebservice();// home-grown XML lookup method for use with app.config file
if (oXMLUtils.getvalue("ProxyYN") == "YES") {
WebProxy proxy = new WebProxy(oXMLUtils.getvalue("ProxyServer"), 1); // proxy location
proxy.BypassProxyOnLocal = true;
GlobalProxySelection.Select = proxy;
ws.Proxy = proxy;
ws.Credentials = new NetworkCredential("mydomain\\myusername", "mypassword"); // not a best practice I suppose
}
return ws;
}