Problem with Relations mapping exposed in a Web Service

81 views
Skip to first unread message

Joil

unread,
Mar 29, 2012, 11:54:32 PM3/29/12
to castle-pro...@googlegroups.com
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 ?

   

Eric Tarasoff

unread,
Mar 30, 2012, 12:18:31 AM3/30/12
to castle-pro...@googlegroups.com
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.



   

--
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 castle-pro...@googlegroups.com.
To unsubscribe from this group, send email to castle-project-u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en.

Joil

unread,
Apr 4, 2012, 2:24:06 PM4/4/12
to castle-pro...@googlegroups.com


El viernes 30 de marzo de 2012 01:18:31 UTC-3, Eric Tarasoff escribió:
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.

you have any example to use DTO, link, code...with ActiveRecord


thanks
 

To post to this group, send email to castle-project-users@googlegroups.com.
To unsubscribe from this group, send email to castle-project-users+unsub...@googlegroups.com.
To post to this group, send email to castle-project-users@googlegroups.com.
To unsubscribe from this group, send email to castle-project-users+unsub...@googlegroups.com.
To post to this group, send email to castle-project-users@googlegroups.com.
To unsubscribe from this group, send email to castle-project-users+unsub...@googlegroups.com.
To post to this group, send email to castle-project-users@googlegroups.com.
To unsubscribe from this group, send email to castle-project-users+unsub...@googlegroups.com.
To post to this group, send email to castle-project-users@googlegroups.com.
To unsubscribe from this group, send email to castle-project-users+unsub...@googlegroups.com.
To post to this group, send email to castle-project-users@googlegroups.com.
To unsubscribe from this group, send email to castle-project-users+unsub...@googlegroups.com.
To post to this group, send email to castle-project-users@googlegroups.com.
To unsubscribe from this group, send email to castle-project-users+unsub...@googlegroups.com.
To post to this group, send email to castle-project-users@googlegroups.com.
To unsubscribe from this group, send email to castle-project-users+unsub...@googlegroups.com.
To post to this group, send email to castle-project-users@googlegroups.com.
To unsubscribe from this group, send email to castle-project-users+unsub...@googlegroups.com.
To post to this group, send email to castle-project-users@googlegroups.com.
To unsubscribe from this group, send email to castle-project-users+unsub...@googlegroups.com.
To post to this group, send email to castle-project-users@googlegroups.com.
To unsubscribe from this group, send email to castle-project-users+unsub...@googlegroups.com.
To post to this group, send email to castle-project-users@googlegroups.com.
To unsubscribe from this group, send email to castle-project-users+unsub...@googlegroups.com.
To post to this group, send email to castle-project-users@googlegroups.com.
To unsubscribe from this group, send email to castle-project-users+unsub...@googlegroups.com.

Jose Pino

unread,
Mar 31, 2012, 12:14:20 AM3/31/12
to castle-pro...@googlegroups.com
El jue, 29-03-2012 a las 21:18 -0700, Eric Tarasoff escribió:
> 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.

you have any example to use DTO, link, code...with ActiveRecord


thanks


>

Eric Tarasoff

unread,
Apr 4, 2012, 5:54:50 PM4/4/12
to castle-pro...@googlegroups.com
You don't really need a hard code example? Basically, imagine something like:
 
var myActiveRecordObjectThatWontSerialize = GetNewInstance();
var simpleDTO = new SimpleDTOThatSerializes();
 
simpleDTO.Field1 = myActiveRecordObjectThatWontSerialize.Field1;
simpleDTO.Field2 = myActiveRecordObjectThatWontSerialize.NestedObject.Field2;
 
etc...you could also possibly use AutoMapper or something like that to kind of automate how that gets done.
 
SimpleDTOThatSerializes is something like:
 
public class SimpleDTOThatSerializes
{
      public string Field1 { get; set; }
      public string Field2 { get; set; }
}
 
Hope that helps...
 
Eric

--
You received this message because you are subscribed to the Google Groups "Castle Project Users" group.
Reply all
Reply to author
Forward
0 new messages