我是.NET/MVC/Web API的新手。我創建了一個接受輸入參數的.Net Web API查詢OracleDatabase並以JSON返回結果。非常接近簡單的C#代碼。我的控制器看起來像配置Web API以提供元數據
public class DataController : ApiController
{
[HttpGet]
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;
}
這很好用。現在客戶端應用程序正在請求元數據。所以他們可以從服務中獲取元數據。我不確定我們是否可以配置現有的API來提供元數據。或者我們將不得不從零開始進行抽菸