![]() |
#18 |
Участник
|
![]()
Server-side asynchronous web method (thanks to Matt Powell)
Реализация асинхронного веб-метода на C#: Код: public class AsyncWebService : System.Web.Services.WebService { public AsyncWebService () { } public delegate string LengthyProcedureAsyncStub( int milliseconds); public string LengthyProcedure(int milliseconds) { System.Threading.Thread.Sleep(milliseconds); return "Success"; } private static IAsyncResult call; private static LengthyProcedureAsyncStub stub; [WebMethod(MessageName="Begin")] public bool BeginLengthyProcedure(int milliseconds) { stub = new LengthyProcedureAsyncStub(LengthyProcedure); call = stub.BeginInvoke(milliseconds, null, null); return true; } [WebMethod(MessageName="End")] public string EndLengthyProcedure() { return stub.EndInvoke(call); } } Вызов из аксапты: Код: WebService w = new WebService ("http://localhost:1584/Test/AsyncWebService.asmx?WSDL"); str s; ; w.BeginLengthyProcedure(5000); s = w.EndLengthyProcedure(); |
|