对Web API的多次异步调用 [英] Multiple async call to Web API
问题描述
您好,
如何使用Webclient进行多个异步Web API调用。下面是我需要将其设置为异步的调用,并且一旦完成所有回调,我需要执行一些操作。下面是我需要使用Webclient调用并行调用的3个调用。
以下是来自MVC控制器的调用。
public JsonResult methodname()
{
使用(var client = new WebClient {UseDefaultCredentials = true})
      {
byte [] test = client.DownloadData(url);
              byte [] test1 = client.DownloadData(url);
              byte [] test3 = client.DownloadData(url);
}
返回Json(.. ..)
}
谢谢......
对方法使用async / await语法:
使用异步和等待的异步编程(C#和Visual Basic)
Hi,
How to make multiple async Web API call using Webclient. Below is the calls I need to make it as async and once all the callback is completed I need to do some operation. Below is the 3 calls I need to call parallel using Webclient.
Below is the call from MVC controller.
public JsonResult methodname()
{
{
byte[] test= client.DownloadData(url );
byte[] test1= client.DownloadData(url);
byte[] test3= client.DownloadData(url);
}
return Json(....)
}
Thanks......
Use the async/await syntax for methods: Asynchronous Programming with Async and Await (C# and Visual Basic)
这篇关于对Web API的多次异步调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!