我正在创建wcf服务,查询Oracle数据库并以JSON格式返回结果。如何将Oracle查询的结果转换为JSON消息
public class Service1 : IService1
{
public HttpResponseMessage GetData(string ROOM)
{
List<OracleParameter> prms = new List<OracleParameter>();
prms.Add(new OracleParameter("ROOM", OracleDbType.Varchar2, ROOM, ParameterDirection.Input));
string connStr = ConfigurationManager.ConnectionStrings["TGSDataBaseConnection"].ConnectionString; using (OracleConnection dbconn = new OracleConnection(connStr))
{
DataSet userDataset = new DataSet();
var strQuery = "SELECT * from LIMS_SAMPLE_RESULTS_VW where ROOM = :ROOM";
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;
}
它会引发错误,如名称&#39;请求&#39;在行
中的当前上下文中不存在var response = Request.CreateResponse(HttpStatusCode.OK, returnObject, MediaTypeHeaderValue.Parse("application/json"));
我添加了
using System.Net.Http;
using System.Net.Http.Formatting;
using System.Net.Http.Headers;
答案 0 :(得分:0)
尝试将Request
更改为HttpContext.Current.Request