Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Recursive XML serialization? XML serialization of cyclic objects?

13 views
Skip to first unread message

"Andrés G. Aragoneses [ knocte ]"

unread,
Jan 11, 2007, 12:18:29 PM1/11/07
to
Hello. I have this kind of object:

class classA
{
int x;
classA z;

public int X
{
get { return this.x; }
set { this.x = value; }
}

public classA Z
{
get { return this.z; }
set { this.z = value; }
}

}

static class Program
{
static void Main(string[] args)
{
classA myObject = new classA();
myObject.X = 2;
myObject.Z = myObject;
}
}


How can I send "myObject" via XML webservice for consumption? I am aware
that this is not possible to be XML-serialized with .NET1.1 but, can I
do it with 2.0 or Indigo?

Thanks in advance,

Andrés [ knocte ]

--

Dave Sexton

unread,
Jan 12, 2007, 7:20:52 AM1/12/07
to
Hi Andrés,

No, it will not work in the 2.0 framework if the XmlSerializer detects a
circular reference.

You can have classA implement IXmlSerializable to handle the serialization.
Another option is to use WCF in the 3.0 framework to handle xml
serialization, which I read in an older article that it allows circular
references:

A. Skonnard, Serialization in Windows Communication Foundation
http://msdn.microsoft.com/msdnmag/issues/06/08/ServiceStation/default.aspx

§ Advanced Serialization Concepts
These new serializers can also maintain object references and deal with
issues like circular references (see the constructor with a
preserveObjectReferences flag). This is a nice improvement over
XmlSerializer, which choked on such object graphs. I can, for example,
serialize a circular spouse reference in the previous examples. I've
included such an example in the downloadable sample code.

I haven't tested this in WCF myself.

Windows Communication Foundation
Serialization and Deserialization
http://msdn2.microsoft.com/en-us/library/ms731073.aspx

--
Dave Sexton
http://davesexton.com/blog

""Andrés G. Aragoneses [ knocte ]"" <kno...@NO-SPAM-PLEASE-gmail.com> wrote
in message news:umZeBSaN...@TK2MSFTNGP02.phx.gbl...

"Andrés G. Aragoneses [ knocte ]"

unread,
Jan 16, 2007, 10:52:18 AM1/16/07
to
Dave Sexton escribió:

> No, it will not work in the 2.0 framework if the XmlSerializer detects a
> circular reference.
>
> You can have classA implement IXmlSerializable to handle the serialization.
> Another option is to use WCF in the 3.0 framework to handle xml
> serialization, which I read in an older article that it allows circular
> references:
>
> A. Skonnard, Serialization in Windows Communication Foundation
> http://msdn.microsoft.com/msdnmag/issues/06/08/ServiceStation/default.aspx
>
> § Advanced Serialization Concepts
> These new serializers can also maintain object references and deal with
> issues like circular references (see the constructor with a
> preserveObjectReferences flag). This is a nice improvement over
> XmlSerializer, which choked on such object graphs. I can, for example,
> serialize a circular spouse reference in the previous examples. I've
> included such an example in the downloadable sample code.
>
> I haven't tested this in WCF myself.
>
> Windows Communication Foundation
> Serialization and Deserialization
> http://msdn2.microsoft.com/en-us/library/ms731073.aspx
>

Thanks! I will take a look into it!

Regards,

Andrés [ knocte ]

--

0 new messages