From: Steve . <mo...@ho...> - 2012-12-04 05:16:49
|
Anyone else using MVC3 or 4 and processing the 'application/sparql-results+json' media type in a media type formatter .... to return a POCO to the controller ? I'm able to return the Json in the Controller this way with this code: var sparqlTask = response.Content.ReadAsStringAsync(); But that requires processing the Json in the controller Since I could not get the media-formatter working --- the conventional approach threw an exception ... note the highlighted code below that I was not able to get to work ... Any members who call Sparql endpoints able to convert json to POCO in a custom media formatter in ASP.Net MVC ??? Thanks, Steve Here the hack that I'd like to replace with a MediaFormatter var task = client.GetAsync(theURL) .ContinueWith((taskWithmsg) => { var response = taskWithmsg.Result; //var sparqlTask = response.Content.ReadAsAsync<operas>(); //var sparqlTask = response.Content.ReadAsAsync<SparqlFormatter>(); var sparqlTask = response.Content.ReadAsStringAsync(); var sparqlObject = sparqlTask.Result; JObject root = JObject.Parse(sparqlObject); JArray _operas = (JArray)root["results"]["bindings"]; sparqlTask.Wait(); model.AddRange( (from JObject jo in _operas select new operas { Opera = jo["Opera"]["value"].ToString(), RingCycleOpera = jo["RingCycleOpera"]["value"].ToString() } )); }); task.Wait(); return View(model); } From: mo...@ho... To: dot...@li... Date: Sun, 18 Nov 2012 14:23:34 -0500 Subject: [dotNetRDF-Develop] ?? MediaTypeFormatter for 'application/sparql-results+json I have an ontology on Knoodl that I need to integrate into an ASP.Net MVC4 web application using ReadAsync method of HttpClient ... (webApi using .Net 4.5) How to fix the exception that I get ?? No MediaTypeFormatter is available to read an object of type 'JArray' from content with media type 'application/sparql-results+json Pointers to how to add a custom MediaTypeFormatter to my solution, please ... or any other way to get this done ?? Hate to have to resort to XML when Json is an option. Articles like this http://byterot.blogspot.com/2012/04/aspnet-web-api-series-part-5.html are helpful, but a bit confusing to me. Thanks, Steve ------------------------------------------------------------------------------ Monitor your physical, virtual and cloud infrastructure from a single web console. Get in-depth insight into apps, servers, databases, vmware, SAP, cloud infrastructure, etc. Download 30-day Free Trial. Pricing starts from $795 for 25 servers or applications! http://p.sf.net/sfu/zoho_dev2dev_nov _______________________________________________ dotNetRDF-develop mailing list dot...@li... https://lists.sourceforge.net/lists/listinfo/dotnetrdf-develop |