开发者

Multiple sequential async web service calls from an asynchronous ASP.NET page?

I need to make n number of async web service calls from an async ASPX page.

Each WS call retrieves a portion of a binary file. The code then outputs the file block to the page's response stream.

offset = 0;
blocksize = 1024;
output = getFileBlock(path, offset, blocksize);

//开发者_开发技巧BinaryWrite output to Response

offset += blocksize;
output = getFileBlock(path, offset, blocksize);

//BinaryWrite output to Response

//etc...

Each getFileBlock is a web service call which I would like to make async. However, I need these calls to happen in a specific order.

Any suggestions how to implement this?


Call the async function. In the async completion handler, output the result, and if you still need more data, call the async function again.

public class Answer
{
  int _offset = 0;
  const int blocksize = 1024;
  string _path;

  static int main()
  {
    Init();
    getFileBlock(_path, _offset, _blocksize);
  }
  void function Init()
  {
    _path = "c:\foo.dat";
    CompletionEvent +=  HandleCompletion;
    getFileBlock(_path, _offset, _blocksize);
  }

  void function HandleCompletion( object sender, CompletionEventArgs e )
  {
    OutputResult( e.Result );
    _offset += blocksize;
    if ( _offset < limit )
    {
      getFileBlock(_path, _offset, _blocksize);
    }
  } 
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜