Web API to Query Oracle DB passing the parameters RRS feed

  • Question

  • User-362386836 posted

    We are currently having a view in the Oracle DB which has almost 16 columns in it. We need to create a Web API that accepts the input parameters and queries the view in the Oracle DB and returns the response in the JSON format. I am new to ASP.NET and the web services. Below is the code for the service

    namespace WebApplication4.Controllers
    public class TGSDataController : ApiController
        public HttpResponseMessage Getdetails([FromUri] string jrs_no)
            List<OracleParameter> prms = new List<OracleParameter>();
            List<string> selectionStrings = new List<string>();
            string connStr = ConfigurationManager.ConnectionStrings["TGSDataConnection"].ConnectionString;
            using (OracleConnection dbconn = new OracleConnection(connStr))
                DataSet userDataset = new DataSet();
                var strQuery = "SELECT * from LIMS_SAMPLE_RESULTS_VW where JRS_NO =" + jrs_no;
                var returnObject = new { data = new OracleDataTableJsonResponses(connStr, strQuery, prms.ToArray()) };
                var response = Request.CreateResponse(HttpStatusCode.OK, returnObject, MediaTypeHeaderValue.Parse("application/json"));
                ContentDispositionHeaderValue contentDisposition = null;
                if (ContentDispositionHeaderValue.TryParse("inline; filename=TGSData.json", out contentDisposition))
                    response.Content.Headers.ContentDisposition = contentDisposition;
                return response;

    I am trying to debug and in the URL I gave like http://localhost:6897/api/TGSData?jrs_no=379 but it throws error like enter image description here

    I am not sure why I am getting the error. I have changed anything or not renamed.Can anyone please help me with this

    Wednesday, November 16, 2016 4:48 AM


  • User-6180675 posted


    public HttpResponseMessage Getdetails([FromUri] string jrs_no)

    You should remove [FromUri] attribute from the argument as you are only passing a querystring as the argument and not a complex type object. [FromUri] attribute is used only when you are sending multiple querystring values or an object of a class as a complex type to the api method.

    Also check the default path for calling the api in webapiconfig.cs file.

    Check the below link for more reference


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 16, 2016 10:16 AM