我写了我的第一个Web api。
namespace WebApi.Controllers
{
public class PersonController : ApiController
{
public IEnumerable<CommonPerson> GetAllPersons()
{
PersonRepository PersonRep = new PersonRepository();
return PersonRep.SelectAll();
}
public IHttpActionResult GetPerson(int id)
{
PersonRepository PersonRep = new PersonRepository();
CommonPerson person = new CommonPerson();
person=PersonRep.SelectByID(id);
if (person == null)
{
return NotFound();
}
return Ok(person);
}
}
}
在测试过程中(使用http://localhost:51855/api/Person/21),出现以下错误:
解析器错误消息:无法加载类型'WebApi.WebApiApplication'。
源错误:
第1行:<%@ Application Codebehind =“ Global.asax.cs” Inherits =“ WebApi.WebApiApplication” Language =“ C#”%>