this is my webapi controller very easy:
public class TreeController : ApiController
{
[HttpGet]
public List<TreeData> GetTreeData()
{
}
}
this is my WebApiConfig:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/json"));
config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver();
//config.Formatters.JsonFormatter.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.All;
config.Formatters.JsonFormatter.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.None;
// Configurazione filtro per global exception handling
// config.Filters.Add(new WebApiUnhandledExceptionFilter());
config.MapHttpAttributeRoutes();
//config.Routes.MapHttpRoute(
// name: "DefaultApi",
// routeTemplate: "api/{controller}/{id}",
// defaults: new { id = RouteParameter.Optional }
//);
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
this is my angular js controller function:
$scope.getTreeData = function () {
$http({
method: "GET",
url: '/api/Tree/GetTreeData',
dataType: "json",
}).then(function successCallback(response) {
$scope.data = response.data;
}, function errorCallback(response) {
alert("trouble..");
});
};
$scope.getTreeData();
why i get 404 ? i need to configure the web.xml ? what i need to do more ?