我有这个 C# 控制器,它通过接收字符串作为输入来执行不同的 SQL 函数。
public HttpResponseMessage GetFunction(string SQLstring)
{
HttpResponseMessage response = new HttpResponseMessage()
{
Content = new StringContent(SQLFunctions.SQLsyncFunctionGet(SQLstring), System.Text.Encoding.UTF8, "application/json")
};
return response;
}
我正在尝试用异步方法重建它:
首先我将 SQL 同步功能更改为异步,没有任何问题:
public async Task<string> SQLasyncFunctionGET(string SQLString)
如何更改
GetFunction
类以在我构建的 Web API 中激活它?
public async Task<IHttpActionResult> GetFunction(string SQLString)
{
var content = await ???????????????
return ok(content);
}
我对这个堆栈不太熟悉,所以我不记得你是否可以返回Task
public async Task<HttpResponseMessage> GetFunction(string SQLstring)
{
HttpResponseMessage response = new HttpResponseMessage()
{
Content = new StringContent(await SQLFunctions.SQLsyncFunctionGet(SQLstring), System.Text.Encoding.UTF8, "application/json")
};
return response;
}