我创建了一个具有以下异步操作的Web API
[ActionName("getFedCust")]
private async Task<HttpResponseMessage> getFedCust()
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://fw.dev.test.com/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = await client.GetAsync("/api/fed");
return response;
}
}
我的控制器名称是ADAccount 当我从Chrome打电话时,我使用以下路线浏览器的操作告诉它无法找到动作getFedCust this link
我已经在WEBapiConfig.cs
中设置了默认路由 config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate:"api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
顺便说一句,如果我创建一个非异步动作,它可以工作
public HttpResponseMessage getFedCust()
{
FedCust[] fedcust = new FedCust[]
{
new FedCust {name="Fabrikam"
,domains="fabrikam.local"
,sts="http://fabrikam.test.com/adfs/services/trust"
},
new FedCust {name="Contoso"
,domains="contoso.local"
,sts="http://contoso.test.com/adfs/services/trust"
}
};
return this.Request.CreateResponse(HttpStatusCode.OK, fedcust, "application/json");
}
任何帮助都会受到欢迎,因为我在该部分非常新手
答案 0 :(得分:2)
我认为您错误地将异步操作定义为“私有”。
private async Task<HttpResponseMessage> getFedCust()
应该是:
public async Task<HttpResponseMessage> getFedCust()