Recursive XML serialization? XML serialization of cyclic objects?

  • Thread starter =?ISO-8859-1?Q?=22Andr=E9s_G=2E_Aragoneses_=5B_kno
  • Start date
?

=?ISO-8859-1?Q?=22Andr=E9s_G=2E_Aragoneses_=5B_kno

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 ]

--
 
D

Dave Sexton

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
 
?

=?ISO-8859-1?Q?=22Andr=E9s_G=2E_Aragoneses_=5B_kno

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 ]

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top