2016-11-18 59 views
0

我創建WCF服務,查詢Oracle數據庫和JSON format.How返回結果的結果從Oracle查詢轉換到JSON消息返回JSON作爲WCF服務的結果

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; 
    } 

它拋出一個喜歡的名字是「請求」錯誤不會在目前的情況下存在於線

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; 

並補充他們的組件作爲參考。但仍表現出了同樣的錯誤。 enter image description here

+0

是什麼反應呢? –

+0

@viveknuna響應是我們從Oracle數據庫 – xyz

回答

0

嘗試改變RequestHttpContext.Current.Request

+0

得到它dosent工作太 – xyz

+1

可以共享錯誤? – Mike

+0

'實例參數:無法從'System.Web.HttpRequest'轉換爲'System.Net.Http.HttpRequestMessage'\t 參數4:無法從'System.Net.Http.Headers.MediaTypeHeaderValue'轉換爲'System.Web。 Http.HttpConfiguration' 'System.Web.HttpRequest'不包含'CreateResponse'的定義和最好的擴展方法重載'System.Net.Http.HttpRequestMessageExtensions.CreateResponse (System.Net.Http.HttpRequestMessage,System.Net .HttpStatusCode,T,System.Web.Http.HttpConfiguration)」具有一些無效arguments' – xyz