D
dzeaman
Hi all!
Maybe my experience will be helpful for someone.
I tried to create server-side asynchronous web-service.
First I found the article of Matt Powell "Server-side asynchronous
web-methods". He advice to use BeginInvoke and EndInvoke for
delegate-methods. But I didn't found how to stop delegate in runtime.
So I try to use method that is not described in MSDN for web-services. Of
course, I didn't invent something new. I just use threading.
First of all I created the private-class TestThread with methods start(),
init() and getResult(). Disadvantage of this method is that you can't send
parameters directly into method, so you need to create init() method for that.
Than I created the thread and web-methods start(), result(), isAlive() and
abort(). Here're they:
private static TestThread testThread;
public static Thread thread;
[WebMethod]
public bool start( string _param )
{
testThread = new TestThread();
testThread.init( _param );
thread = new Thread( new ThreadStart( testThread.start ) );
thread.Start();
return true;
}
[WebMethod]
public bool result()
{
return testThread.getResult();
}
[WebMethod]
public bool isAlive()
{
return thread.IsAlive;
}
[WebMethod]
public bool abort()
{
thread.Abort();
return true;
}
I realize you'll understand this idea.
Callback is also not so hard.
private static ProcessInfo processInfo;
[WebMethod]
public string getProcessInfo()
{
return processInfo.getInfo();
}
And the class:
public class ProcessInfo
{
private static string info;
public string getInfo()
{
string result = info;
info = "";
return result;
}
public string addInfo( string _info )
{
info += _info;
return info;
}
}
That's all.
Best regards,
Andrey Dzizenko.
Maybe my experience will be helpful for someone.
I tried to create server-side asynchronous web-service.
First I found the article of Matt Powell "Server-side asynchronous
web-methods". He advice to use BeginInvoke and EndInvoke for
delegate-methods. But I didn't found how to stop delegate in runtime.
So I try to use method that is not described in MSDN for web-services. Of
course, I didn't invent something new. I just use threading.
First of all I created the private-class TestThread with methods start(),
init() and getResult(). Disadvantage of this method is that you can't send
parameters directly into method, so you need to create init() method for that.
Than I created the thread and web-methods start(), result(), isAlive() and
abort(). Here're they:
private static TestThread testThread;
public static Thread thread;
[WebMethod]
public bool start( string _param )
{
testThread = new TestThread();
testThread.init( _param );
thread = new Thread( new ThreadStart( testThread.start ) );
thread.Start();
return true;
}
[WebMethod]
public bool result()
{
return testThread.getResult();
}
[WebMethod]
public bool isAlive()
{
return thread.IsAlive;
}
[WebMethod]
public bool abort()
{
thread.Abort();
return true;
}
I realize you'll understand this idea.
Callback is also not so hard.
private static ProcessInfo processInfo;
[WebMethod]
public string getProcessInfo()
{
return processInfo.getInfo();
}
And the class:
public class ProcessInfo
{
private static string info;
public string getInfo()
{
string result = info;
info = "";
return result;
}
public string addInfo( string _info )
{
info += _info;
return info;
}
}
That's all.
Best regards,
Andrey Dzizenko.