[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.webservices

Server-Side Asynchronous Web Method help

Simple Simon

8/13/2003 5:08:00 AM

Hi, please excuse the long post and plz read on :)

note: also posted in microsoft.public.dotnet.framework.aspnet

My web application needs to upload a .csv & .zip file, as well as,
import the .csv into a (Sql2000) table and unzip the .zip file to a
directory on the web server every day. Since I don't want the
application to time-out, I'm putting all this into a Server-Side
Asynchronous Web Method.

I've starting out by writing this test web service:

public delegate string GetListingsAsyncStub(int DelayInSeconds);

public string GetListings(int DelayInSeconds)
{
if (DelayInSeconds > 0)
{
System.Threading.Thread.Sleep(DelayInSeconds * 1000);
}
return "Success";
}

public class MyState
{
public object previousState;
public GetListingsAsyncStub asyncStub;
}

[WebMethod]
public IAsyncResult BeginGetListings(int DelayInSeconds, AsyncCallback
callback, object asyncState)
{
GetListingsAsyncStub stub = new
GetListingsAsyncStub(GetListings);

MyState ms = new MyState();
ms.previousState = asyncState;
ms.asyncStub = stub;

return stub.BeginInvoke(DelayInSeconds, callback, ms);
}

[WebMethod]
public string EndGetListings(IAsyncResult asyncResult)
{
MyState ms = (MyState)asyncResult.AsyncState;
return ms.asyncStub.EndInvoke(asyncResult);
}


And this is in my Page_Load page that will be scheduled to run:

string ReturnValue;
IAsyncResult AsyncResult;

ImportService service = new ImportService();

Response.Write("Started: " + DateTime.Now.ToString() + "<br>");
AsyncResult = service.BeginGetListings(10, null, null);

ReturnValue = service.EndGetListings(AsyncResult);
Response.Write("Ended: " + DateTime.Now.ToString() + "<br>");

Response.Write(ReturnValue);


What I'm seeing is, the page waits for the ten seconds to load. Does
ne1 see the obvious(to you) reason?

TIA,
~Gordon
1 Answer

Simple Simon

8/13/2003 5:47:00 AM

0

Should i be using Delegates? Check out this article...about half-way
down:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnservice/html/service10...
Delegates will cause the asynchronous method calls to execute on a
thread in the process thread pool. Unfortunately, these are the same
threads used by the ASMX handler to service incoming requests

On Tue, 12 Aug 2003 22:35:57 -0700, "krishna" <kjammula@solucient.com>
wrote:

>Yes, because you are listening for response on a single
>IO thread. You need to register a callback in your client
>and pass it to the webservice to have webservice call
>your callback delegate.
>AsyncResult = service.BeginGetListings(10, callback,
>null);
>you are passing null as 2nd argument.
>I was having problems marshalling webservice results from
>callback delegate to asp.net IO thread.
>Krishna
>>-----Original Message-----
>>Hi, please excuse the long post and plz read on :)
>>
>>note: also posted in
>microsoft.public.dotnet.framework.aspnet
>>
>>My web application needs to upload a .csv & .zip file,
>as well as,
>>import the .csv into a (Sql2000) table and unzip
>the .zip file to a
>>directory on the web server every day. Since I don't
>want the
>>application to time-out, I'm putting all this into a
>Server-Side
>>Asynchronous Web Method.
>>
>>I've starting out by writing this test web service:
>>
>>public delegate string GetListingsAsyncStub(int
>DelayInSeconds);
>>
>>public string GetListings(int DelayInSeconds)
>>{
>> if (DelayInSeconds > 0)
>> {
>> System.Threading.Thread.Sleep
>(DelayInSeconds * 1000);
>> }
>> return "Success";
>>}
>>
>>public class MyState
>>{
>> public object previousState;
>> public GetListingsAsyncStub asyncStub;
>>}
>>
>>[WebMethod]
>>public IAsyncResult BeginGetListings(int DelayInSeconds,
>AsyncCallback
>>callback, object asyncState)
>>{
>> GetListingsAsyncStub stub = new
>>GetListingsAsyncStub(GetListings);
>>
>> MyState ms = new MyState();
>> ms.previousState = asyncState;
>> ms.asyncStub = stub;
>>
>> return stub.BeginInvoke(DelayInSeconds, callback,
>ms);
>>}
>>
>>[WebMethod]
>>public string EndGetListings(IAsyncResult asyncResult)
>>{
>> MyState ms = (MyState)asyncResult.AsyncState;
>> return ms.asyncStub.EndInvoke(asyncResult);
>>}
>>
>>
>>And this is in my Page_Load page that will be scheduled
>to run:
>>
>>string ReturnValue;
>>IAsyncResult AsyncResult;
>>
>>ImportService service = new ImportService();
>>
>>Response.Write("Started: " + DateTime.Now.ToString()
>+ "<br>");
>>AsyncResult = service.BeginGetListings(10, null, null);
>>
>>ReturnValue = service.EndGetListings(AsyncResult);
>>Response.Write("Ended: " + DateTime.Now.ToString()
>+ "<br>");
>>
>>Response.Write(ReturnValue);
>>
>>
>>What I'm seeing is, the page waits for the ten seconds
>to load. Does
>>ne1 see the obvious(to you) reason?
>>
>>TIA,
>>~Gordon
>>.
>>