我已经创建了一个OData服务来插入数据库:
OData控制器:
public class ReportParameterController : ODataController
{
private ReportChatBotModel db = new ReportChatBotModel();
[HttpPost]
[ODataRoute("PostReportParameter")]
public IHttpActionResult Post(ReportParameterData data)
{
var reportParameter = new ReportParameter { Year = data.Year, IsLatest = true };
switch (data.Period)
{
case "Quarter One":
reportParameter.Quarter = "1";
break;
case "Quarter Two":
reportParameter.Quarter = "2";
break;
case "Quarter Three":
reportParameter.Quarter = "3";
break;
case "Quarter Four":
reportParameter.Quarter = "4";
break;
default:
return BadRequest();
}
db.ReportParameters.Add(reportParameter);
db.SaveChanges();
return Ok();
}
我使用http客户端编写了一个web api来调用上面的服务:
using (var client = new HttpClient())
{
var values = new ReportParameterData { Year = year, Period = period };
client.BaseAddress = new Uri("https://myTestHost:44307/ChatBot.Services");
var responseString = await client.PostAsJsonAsync("odata/PostReportParameter", values)
.ContinueWith((postTask) => postTask.Result.EnsureSuccessStatusCode());
}
我使用Postman来调用OData服务,它工作正常,但是当我尝试使用web api来使用OData服务时,错误消息是404 Not Found.Any建议弄清楚什么是根源?非常感谢!!