private string GetArtist() { var response = new JsonResponseMessage(); var jSearializer = new System.Web.Script.Serialization.JavaScriptSerializer(); try { List<Artist> results; using (var ormContext = new ChinookContext()) { results = ormContext.Artists.ToList(); } // var results = this.contexts1.Artists.ToList(); response.IsSucess = true; response.Message = string.Empty; response.CallBack = this.callBackMethodName; response.ResponseData = results; } catch (Exception ex) { response.Message = ex.Message; response.IsSucess = false; } return jSearializer.Serialize(response); }
//public HttpResponseMessage<JsonPReturn> Get(int id, string callback) // Changed for Web Api RC // GET /api/values/5 public string Get() { var _response = new JsonResponseMessage(); var jSearializer = new System.Web.Script.Serialization.JavaScriptSerializer(); _response.IsSucess = true; _response.Message = string.Empty; _response.CallBack = string.Empty; _response.ResponseData = "This is a test"; //context.Response.Write(jSearializer.Serialize(_response)); // return Request.CreateResponse(HttpStatusCode.Created, "{'id':'" + id.ToString(CultureInfo.InvariantCulture) + "','data':'Hello JSONP'}"); //var ret = // new HttpResponseMessage<JsonPReturn>( // new JsonPReturn // { // CallbackName = callback, // Json = "{'id':'" + id.ToString(CultureInfo.InvariantCulture) + "','data':'Hello JSONP'}" // }); //ret.Content.Headers.ContentType = new MediaTypeHeaderValue("application/javascript"); //return ret; return jSearializer.Serialize(_response); }