WCF restful returning JSON by using Entity Framework Complex -


recently have set wcf restful service ef4. worked out when returning xml format response. when comes json, got 504 error. unable return json data, wcf resful service .net 4.0

by digging deeper using service trace viewer: found error:

'the type 'xxx.dataentity.appview' cannot serialized json because isreference setting 'true'. json format not support references because there no standardized format representing references. enable serialization, disable isreference setting on type or appropriate parent class of type.'

the "appview" complex object class generated ef4 store procedure. spend quite bit time google how disable isreference, little result far.

anyone? solutions?

thanks in advance

code:

[operationcontract]         [webinvoke(method = "get",             bodystyle = webmessagebodystyle.wrapped,             uritemplate = "app/{id}/{format}")]         appview funcdetail(string id, string format);    public appview funcdetail(string id, string format)         {             setresponseformat(format);             return appsvcs.getbyid(id);         }   private void setresponseformat(string format)             {                 if (format.tolower() == "json")                 {                     responsecontext.format = webmessageformat.json;                 }                 else                 {                     responsecontext.format = webmessageformat.xml;                 }             } 

i ran same issue. happened on 1 of service methods trying return json serialised entity objects. other methods returning json serialised data transfer objects (dtos), stand-alone , not connected entity framework. using dtos data posted methods. often, data send out not need data store in model or database e.g. id values, updated dates, etc. mapping done in model class, so:

public partial class location {      public static locationdto createlocationdto(location location)     {         locationdto dto = new locationdto         {             accuracy = location.accuracy,             altitude = location.altitude,             bearing = location.bearing                         };         return dto;     } 

it may seem bit clunky works , ensures send data fields intended send back. works me because have 5 or 6 entities can see bit tedious if have lots of classes.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -