I am having a working Web API application which has the controller called StudyDataController which accepts the input parameters, queries Database and returns result in JSON.That piece is working fine. Calling http://localhost:3214/api/StudyDataController?param1=R01¶m2=05-NOV-16 returns result.
public class StudyDataController : ApiController
{ [HttpGet]
public HttpResponseMessage Getdetails(string param1, DateTime param2)
{
List<OracleParameter> p = new List<OracleParameter>();
p.Add(new OracleParameter("param1", OracleDbType.Varchar2,param1, ParameterDirection.Input));
p.Add(new OracleParameter("param2",OracleDbType.Date,param2, ParameterDirection.Input));
string connStr = ConfigurationManager.ConnectionStrings["StudyDataConnection"].ConnectionString;
using (OracleConnection dbconn = new OracleConnection(connStr))
{
DataSet userDataset = new DataSet();
var strQuery = "SELECT * from Studydata_VW where Request_id = :param1 and RequestDate > :param2 ";
var returnObject = new { data = new OracleDataTableJsonResponse(connStr, strQuery, prms.ToArray()) };
var response = Request.CreateResponse(HttpStatusCode.OK, returnObject, MediaTypeHeaderValue.Parse("application/json"));
ContentDispositionHeaderValue contentDisposition = null;
if (ContentDispositionHeaderValue.TryParse("inline; filename=StudyData.json", out contentDisposition))
{
response.Content.Headers.ContentDisposition = contentDisposition;
}
return response;
}}}
But I now need to create a one more API has different input parameters and query is different and returns result in JSON. For this I am trying to create one Controller called StudyDatawithDateController on the same application.
public class StudyDatawithDateController : ApiController
{ [HttpGet]
public HttpResponseMessage Getdetails(DateTime param1,String param2)
{
List<OracleParameter> p = new List<OracleParameter>();
p.Add(new OracleParameter("param1",OracleDbType.Date,param1, ParameterDirection.Input));
p.Add(new OracleParameter("param2", OracleDbType.Varchar2,param2, ParameterDirection.Input));
string connStr = ConfigurationManager.ConnectionStrings["StudyDataConnection"].ConnectionString;
using (OracleConnection dbconn = new OracleConnection(connStr))
{
DataSet userDataset = new DataSet();
var strQuery = "SELECT * from Studydata_VW where Submit_date> :param1 and Status = :param2 ";
var returnObject = new { data = new OracleDataTableJsonResponse(connStr, strQuery, prms.ToArray()) };
var response = Request.CreateResponse(HttpStatusCode.OK, returnObject, MediaTypeHeaderValue.Parse("application/json"));
ContentDispositionHeaderValue contentDisposition = null;
if (ContentDispositionHeaderValue.TryParse("inline; filename=StudyDatawithDate.json", out contentDisposition))
{
response.Content.Headers.ContentDisposition = contentDisposition;
}
return response;
}}}
If I try to call the endpoint like http://localhost:3214/api/StudyDatawithDateController?param1=01-NOV-16¶m2=COMPLETE it says Not Found Error.

The webConfig.cs is like below
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
Can we have two controllers on the same WebAPI application. Most of the questions/Samples are discussing about having same name controllers. But here I am having different names and how can I deal with this.
StudyDatControllermissing ana?