[Mono-list] Recursive XML serialization? XML serialization of cyclic objects?

"Andrés G. Aragoneses [ knocte ] "Andrés G. Aragoneses [ knocte ]
Fri Jan 12 06:55:29 EST 2007


Hi Robert, thanks for your answer!

Robert Jordan escribió:
> Andrés G. Aragoneses [ knocte ] wrote:
>> Having 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?
> 
> I'm not aware of any Web Service standard allowing that
> kind of cycles.

Neither if I create my custom XmlSerializer? How can I tell my ASP.NET 
webservice to use it instead of the default one?


> If you really need such complex classes and you don't

Well, it's not that complex to have a domain model that allows it. For 
example, a very common scenario:

public class Parameter {
   public Client Parent;
   public int Value;
}

public class Client {
   public List<Parameter> Parameters;
}

Parameter parameter = new Parameter();
Client client = new Client();
parameter.Parent = client;
parameter.Value = 3;
client.Parameters = new List<Parameter>();
client.Parameters.Add(parameter);


The 'client' object then is an example of what can be retrieved from an 
Object-Relational Mapping Framework. It has a list that represents the 
1-N relation, and the parameter has a reference to the parent object 
(N-1 relation).


> care about interop, you could switch to XSP/ASP.NET-hosted
> .NET Remoting using a HttpChannel. This would require to design
> the classes [Serializable], which is an issue of its own, though.

Yes, this is the temporary workaround we are using: binary 
serialization. But this is kind of hackish and also I think that in the 
future we will need to parse the objects via XSLT; that's why I'm 
interested in XML serialization.


> Anyway, my strong opinion is: *never* employ remoting or Web Services
> w/out a remoting facade pattern that maps between complex objects
> and simple (remotable) objects.

Well, I think I understand your concern about this. However I think we 
were using this pattern until we realised we had to write many code for 
each class of the domain model so as to write these translation 
mechanisms. Then we opted for a totally transparent solution that, 
however, needs a reflection-based conversion so as to mark some parts of 
the objects as "lazy" (not retrieved) and be able to serialize them.

In case you are interested, I wrote a blog post about it (it's based on 
NHibernate mapping framework; oh! and sorry, it's written in Spanish but 
perhaps you can more or less understand it using the automatic 
translation service link I have at the top of the page).

Regards,

	Andrés	[ knocte ]

-- 



More information about the Mono-list mailing list