You might not like this answer but in situations like this, or even in Ajax situations, we use DTOs. Serializing complex object graphs (or even not so complex ones) always seems to be problematic.
On Thu, Mar 29, 2012 at 8:54 PM, Joil <[email protected]> wrote: > Hi people, I have a problem with Relations mapping exposed in a Web Service > > Model > > [ActiveRecord] > public class Ticket : ActiveRecordValidationBase<Ticket> > { > private IList _followup = new ArrayList(); > > [PrimaryKey(PrimaryKeyType.Native)] > public int Id { > get; set; > } > ... > ... > [HasMany(typeof(Followup), Inverse = true, Table="Followup", > ColumnKey="TicketId")] > public IList Followups > { > get { return _followup; } > set { _followup = value; } > } > } > > [ActiveRecord] > public class Followup : ActiveRecordValidationBase<Followup> > { > private Ticket _ticket; > > [PrimaryKey(PrimaryKeyType.Native)] > public int Id { > get; set; > } > ... > ... > [BelongsTo("TicketId")] > public Ticket TicketRef > { > get { return _ticket; } > set { _ticket = value; } > } > } > > > Web Serbice > > public class ws : System.Web.Services.WebService > { > [WebMethod()] > public Ticket[] ListAllTicket() { > return (Ticket[]) Ticket.FindAll(typeof(Ticket)); > } > } > > > Error Invoke WebMethod, output : > > 500 - Internal Server Error > System.InvalidOperationException: There was an error generating the XML > document. ---> System.InvalidOperationException: A circular reference was > detected while serializing an object of type Ticket > at System.Xml.Serialization.XmlSerializationWriter.WriteStartElement > (System.String name, System.String ns, System.Object o, Boolean > writePrefixed, ICollection namespaces) [0x00000] in <filename unknown>:0 > at System.Xml.Serialization.XmlSerializationWriter.WriteStartElement > (System.String name, System.String ns, System.Object o, Boolean > writePrefixed) [0x00000] in <filename unknown>:0 > at System.Xml.Serialization.XmlSerializationWriter.WriteStartElement > (System.String name, System.String ns, System.Object o) [0x00000] in > <filename unknown>:0 > at > System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteObject > (System.Xml.Serialization.XmlTypeMapping typeMap, System.Object ob, > System.String element, System.String namesp, Boolean isNullable, Boolean > needType, Boolean writeWrappingElem) [0x00000] in <filename unknown>:0 > at > System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteMemberElement > (System.Xml.Serialization.XmlTypeMapElementInfo elem, System.Object > memberValue) [0x00000] in <filename unknown>:0 > at > System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteElementMembers > (System.Xml.Serialization.ClassMap map, System.Object ob, Boolean > isValueList) [0x00000] in <filename unknown>:0 > at > System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteObjectElementElements > (System.Xml.Serialization.XmlTypeMapping typeMap, System.Object ob) > [0x00000] in <filename unknown>:0 > at > System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteObjectElement > (System.Xml.Serialization.XmlTypeMapping typeMap, System.Object ob, > System.String element, System.String namesp) [0x00000] in <filename > unknown>:0 > at > System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteObject > (System.Xml.Serialization.XmlTypeMapping typeMap, System.Object ob, > System.String element, System.String namesp, Boolean isNullable, Boolean > needType, Boolean writeWrappingElem) [0x00000] in <filename unknown>:0 > at > System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteMemberElement > (System.Xml.Serialization.XmlTypeMapElementInfo elem, System.Object > memberValue) [0x00000] in <filename unknown>:0 > at > System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteListContent > (System.Object container, System.Xml.Serialization.TypeData listType, > System.Xml.Serialization.ListMap map, System.Object ob, > System.Text.StringBuilder targetString) [0x00000] in <filename unknown>:0 > at > System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteMemberElement > (System.Xml.Serialization.XmlTypeMapElementInfo elem, System.Object > memberValue) [0x00000] in <filename unknown>:0 > at > System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteElementMembers > (System.Xml.Serialization.ClassMap map, System.Object ob, Boolean > isValueList) [0x00000] in <filename unknown>:0 > at > System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteObjectElementElements > (System.Xml.Serialization.XmlTypeMapping typeMap, System.Object ob) > [0x00000] in <filename unknown>:0 > at > System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteObjectElement > (System.Xml.Serialization.XmlTypeMapping typeMap, System.Object ob, > System.String element, System.String namesp) [0x00000] in <filename > unknown>:0 > at > System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteObject > (System.Xml.Serialization.XmlTypeMapping typeMap, System.Object ob, > System.String element, System.String namesp, Boolean isNullable, Boolean > needType, Boolean writeWrappingElem) [0x00000] in <filename unknown>:0 > at > System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteMemberElement > (System.Xml.Serialization.XmlTypeMapElementInfo elem, System.Object > memberValue) [0x00000] in <filename unknown>:0 > at > System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteListContent > (System.Object container, System.Xml.Serialization.TypeData listType, > System.Xml.Serialization.ListMap map, System.Object ob, > System.Text.StringBuilder targetString) [0x00000] in <filename unknown>:0 > at > System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteListElement > (System.Xml.Serialization.XmlTypeMapping typeMap, System.Object ob, > System.String element, System.String namesp) [0x00000] in <filename > unknown>:0 > at > System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteObject > (System.Xml.Serialization.XmlTypeMapping typeMap, System.Object ob, > System.String element, System.String namesp, Boolean isNullable, Boolean > needType, Boolean writeWrappingElem) [0x00000] in <filename unknown>:0 > at System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteRoot > (System.Object ob) [0x00000] in <filename unknown>:0 > at System.Xml.Serialization.XmlSerializer.Serialize (System.Object o, > System.Xml.Serialization.XmlSerializationWriter writer) [0x00000] in > <filename unknown>:0 > at System.Xml.Serialization.XmlSerializer.Serialize > (System.Xml.XmlWriter writer, System.Object o, > System.Xml.Serialization.XmlSerializerNamespaces namespaces) [0x00000] in > <filename unknown>:0 > --- End of inner exception stack trace --- > at System.Xml.Serialization.XmlSerializer.Serialize > (System.Xml.XmlWriter writer, System.Object o, > System.Xml.Serialization.XmlSerializerNamespaces namespaces) [0x00000] in > <filename unknown>:0 > at System.Xml.Serialization.XmlSerializer.Serialize > (System.Xml.XmlWriter xmlWriter, System.Object o) [0x00000] in <filename > unknown>:0 > at System.Web.Services.Protocols.XmlReturnWriter.Write > (System.Web.HttpResponse response, System.IO.Stream outputStream, > System.Object returnValue) [0x00000] in <filename unknown>:0 > at > System.Web.Services.Protocols.HttpSimpleWebServiceHandler.ProcessRequest > (System.Web.HttpContext context) [0x00000] in <filename unknown>:0 > > > > Any idea, how to fix ? > > > > -- > You received this message because you are subscribed to the Google Groups > "Castle Project Users" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/castle-project-users/-/YtDffUjnwfgJ. > To post to this group, send email to [email protected] > . > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/castle-project-users?hl=en. > -- You received this message because you are subscribed to the Google Groups "Castle Project Users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en.
