Re: Asynchronous Call Pattern Problem #2
- From: "John Saunders [MVP]" <john.saunders at trizetto.com>
- Date: Wed, 11 Jul 2007 11:37:06 -0400
"lucius" <lucius@xxxxxxxxxxxxxxxx> wrote in message news:2qs993l9t7v26o5pvvqlvdjq5t3qonnpch@xxxxxxxxxx
My async web method does not seem to be truly asynchronous. My
webmethod is supposed to immediately return "nothing" to a calling
client while it makes its own webservice call to another remote thing.
Could someone tell me how to make this better? It seems like my
webmethod is still holding up the client while it makes its own remote
call instead of immediately returning.
public object prevstate;
public asyncstub myasyncstub;
public delegate List<BaseCommand> asyncstub( Invoker commandinvoker ,
List<BaseCommand> commandlist );
public List<BaseCommand> InvokerExec( Invoker commandinvoker ,
List<BaseCommand> commandlist )
{
using ( commandinvoker )
{
foreach ( BaseCommand command in commandlist )
{
// command has a "Do()" method that does the remote WS
call...
commandinvoker.ExecuteCommand( command );
// this is where the present web service hangs until the
remote web service completes
}
}
return commandlist;
}
public class invokerexecstate
{
public object prevstate;
public asyncstub myasyncstub;
}
[WebMethod]
public IAsyncResult BeginReq( string requestthing , AsyncCallback
asyncCallBack , object memstore )
{
List<BaseCommand> wantedCommands = new List<BaseCommand>();
MyCommand commandinstance = new MyCommand(requestthing);
wantedCommands.Add( commandinstance );
Invoker commandinvoker = new Invoker();
myasyncstub = new asyncstub( InvokerExec );
invokerexecstate localstate = new invokerexecstate();
localstate.prevstate = memstore;
localstate.myasyncstub = myasyncstub;
return myasyncstub.BeginInvoke( commandinvoker ,
wantedCommands , asyncCallBack , localstate );
}
[WebMethod]
public void EndReq( IAsyncResult completedResult )
{
invokerexecstate localstate =
(invokerexecstate)completedResult.AsyncState;
List<BaseCommand> completedCommands =
(List<BaseCommand>)localstate.myasyncstub.EndInvoke( completedResult
);
}
Can you simplify this example? Your problem probably has nothing to do with your BaseCommand class, for instance, so can you abstract that out?
--
John Saunders [MVP]
.
- Follow-Ups:
- Re: Asynchronous Call Pattern Problem #2
- From: lucius
- Re: Asynchronous Call Pattern Problem #2
- From: Steven Cheng[MSFT]
- Re: Asynchronous Call Pattern Problem #2
- References:
- Asynchronous Call Pattern Problem #2
- From: lucius
- Asynchronous Call Pattern Problem #2
- Prev by Date: Asynchronous Call Pattern Problem #2
- Next by Date: Re: Asynchronous Call Pattern Problem #2
- Previous by thread: Asynchronous Call Pattern Problem #2
- Next by thread: Re: Asynchronous Call Pattern Problem #2
- Index(es):
Loading