我创建了以下mvc web api控制器操作
public HttpResponseMessage Post(Model model)
{
var response = Request.CreateResponse(HttpStatusCode.Created, model);
return response;
}
并从以下网络请求中调用它一切正常
var webClient = new WebClient(); webClient.UploadValues(uri," POST",valuesToPost);
然后,如果我尝试使用UploadValuesAsync而不是UploadValues,则永远不会达到web api操作。 有任何想法吗?我是否必须将web api操作声明为异步操作?我试过了,但没有工作。
谢谢!
答案 0 :(得分:0)
经过一些尝试,通过像这样修改api来实现它:
public async Task<HttpResponseMessage> Post(Model model)
{
var response = Request.CreateResponse(HttpStatusCode.Created, model);
await Task.Run(() => DoSomething());
return response;
}
希望它可以帮助别人。