Connecting Tech Pros Worldwide Forums | Help | Site Map

XML Serialization in .NET

Member
 
Join Date: Mar 2008
Posts: 81
#1: Oct 6 '08
Hey All,
I am using a C# client that generates xml that then gets sent via a web service to a java web service server side. In this case, we are creating the messages ourselves, based on the contract defined by the java wsdl.

I am looking for some advice on what the best approach is for this. Currently, on the client, my classes for Objects just wrap xml. This means If I had a person object, and I did:
Person p = new Person(PersonElement);
p.firstName;
p.firstName = "NewName";

the getter would be actually running an xpath to the attribute, and the same with the set. When I want the xml output, it's simple because I just get the Element that the object is wrapping.

However, this seems like it would be expensive compared to using an object, and then just serializing/deserializing when needed.

I have played around a little with XMLSerializer, and I have looked at DataContractSerializer. Problem with DCS is that you cannot specify what is an attribute, and what is an element.

Is there anything in .NET similar to JAXB in java, or is XMLSerializer the closest thing?

Thanks so much!

joedeene's Avatar
Site Addict
 
Join Date: Jul 2008
Location: US of A
Posts: 587
#2: Oct 7 '08

re: XML Serialization in .NET


Quote:

Originally Posted by nelsonbrodyk

Hey All,
I am using a C# client that generates xml that then gets sent via a web service to a java web service server side. In this case, we are creating the messages ourselves, based on the contract defined by the java wsdl.

I am looking for some advice on what the best approach is for this. Currently, on the client, my classes for Objects just wrap xml. This means If I had a person object, and I did:
Person p = new Person(PersonElement);
p.firstName;
p.firstName = "NewName";

the getter would be actually running an xpath to the attribute, and the same with the set. When I want the xml output, it's simple because I just get the Element that the object is wrapping.

However, this seems like it would be expensive compared to using an object, and then just serializing/deserializing when needed.

I have played around a little with XMLSerializer, and I have looked at DataContractSerializer. Problem with DCS is that you cannot specify what is an attribute, and what is an element.

Is there anything in .NET similar to JAXB in java, or is XMLSerializer the closest thing?

Thanks so much!

Well, for one, this seems to me that it is in the wrong forum. Also, have a look at this MSDN site for the XmlSerializer Class. Ya, just read that and see what you think...

joedeene
Reply