Показать сообщение отдельно
Старый 16.12.2005, 19:34   #18  
dzeaman is offline
dzeaman
Участник
 
21 / 10 (1) +
Регистрация: 29.09.2005
Адрес: Санкт-Петербург
Post Результат
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();