471,594 Members | 1,888 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,594 software developers and data experts.

Recursive XML serialization? XML serialization of cyclic objects?

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 ]

--
Jan 11 '07 #1
2 9256
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/is...n/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 ]"" <kn****@NO-SPAM-PLEASE-gmail.comwrote
in message news:um**************@TK2MSFTNGP02.phx.gbl...
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 ]

--

Jan 12 '07 #2
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/is...n/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 ]

--
Jan 16 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Maximus | last post: by
2 posts views Thread by skip | last post: by
3 posts views Thread by from.future.import | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.