I have an MVC application, that contains a web application in a simple mvc 4 project. Moreover I have a Windows application, that is a windows execution of the web application in an other windows application project.
The Windows application uses MVC API and makes calls to the MVC Web Application Controller by the name of TfsApiController by a resthelper class.
All the methods are working except the post method. I want to post an object to the tfsapi controller.
The post method of rest helper class:
public void Post(T targetObject)
{
if (targetObject == null)
{
throw new System.ArgumentNullException("targetObject");
}
//Get formatting details.
System.Net.Http.Formatting.MediaTypeFormatter myFormatter = new XmlMediaTypeFormatter();
myUrlSuffix = "api/tfsapi";
//Make the call.
var result = this.MainHttpClient.PostAsync(myUrlSuffix, targetObject, myFormatter).Result.Content.ReadAsAsync<T>().Result;
}
My TfsApiController method:
public void PostPreActivity(PreActivity preActivity)
{
}
And the Routing:
RouteTable.Routes.MapHttpRoute(
name: "PostPreActivity",
routeTemplate: "api/tfsapi/Post",
defaults: new { id = RouteParameter.Optional }
).RouteHandler = new SessionRouteHandler();
I wasted lot of hours, but i do not know what is the problem.
UPDATE:
This is my all routings:
RouteTable.Routes.MapHttpRoute(
name: "GetWorkItemsByProject",
routeTemplate: "api/{controller}/{action}/{projectID}",
defaults: new { controller = "tfsapi", action = "GetWorkItems", projectID = UrlParameter.Optional }
).RouteHandler = new SessionRouteHandler();;
RouteTable.Routes.MapHttpRoute(
name: "ActionWebApiRoute",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
).RouteHandler = new SessionRouteHandler();
RouteTable.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
).RouteHandler = new SessionRouteHandler();