来自异步 ASP.NET 页面的多个顺序异步 Web 服务调用?

发布于 2024-08-07 05:43:43 字数 426 浏览 6 评论 0原文

我需要从异步 ASPX 页面进行 n 次异步 Web 服务调用。

每个 WS 调用都会检索二进制文件的一部分。然后,代码将文件块输出到页面的响应流。

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...

每个 getFileBlock 都是一个 Web 服务调用,我想将其进行异步。但是,我需要这些调用按特定顺序进行。

有什么建议如何实施?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅唱々樱花落 2024-08-14 05:43:43

调用异步函数。在异步完成处理程序中,输出结果,如果仍需要更多数据,请再次调用异步函数。

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);
    }
  } 
}

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);
    }
  } 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文