trx trx - 11 months ago 64
ASP.NET (C#) Question

Configure Web API to provide metadata

I am new to.NET /MVC/ Web API. I have created a .Net Web API which accepts the input parameters Queries the OracleDatabase and returns the result in JSON. Pretty much following the simple C# codes. My Controller looks like

public class DataController : ApiController
public HttpResponseMessage Getdetails(string ROOM, DateTime DOB_GT)
List<OracleParameter> prms = new List<OracleParameter>();
prms.Add(new OracleParameter("ROOM", OracleDbType.Varchar2, ROOM, ParameterDirection.Input));
prms.Add(new OracleParameter("DOB_GT", OracleDbType.Date, DOB_GT, ParameterDirection.Input));
string connStr = ConfigurationManager.ConnectionStrings["SDataBaseConnection"].ConnectionString;
using (OracleConnection dbconn = new OracleConnection(connStr))
DataSet userDataset = new DataSet();
var strQuery = "SELECT * from SAMPLE_RESULTS_VW where ROOM = :ROOM and DOB > :DOB_GT ";
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=TGSData.json", out contentDisposition))
response.Content.Headers.ContentDisposition = contentDisposition;
return response;

This works perfectly. Now the Client application is requesting for the metadata. So they can pull in the metadata from the service. I am not sure if we can configure the existing API to provide metadata. Or we will have to do smoething from the scratch

Answer Source

There are some projects available in the form of NuGet packages that can help you do this. So no need to write it from scratch.

You can add Swagger to provide metadata of your api. See and

Using the Asp.Net Web Api helppages ( you can add WADL support using