Craig remains jumpy about XmlSerializer and element order...

Craig posted a rebuttal to my earlier post. I maintain that his original advice to implement IXmlSerializable is overkill. His argument is that you're in trouble unless you “explicitly control the order of serialization of [your] web service visible types“. I agree, except that I substitute “implicit“ for “explicit“. In either .NET 1.x or 2.0, you exercise implicit control by controlling the order of the properties or fields in your type. In .NET 2.0, you can also “explicitly“ control this using the XmlElementAttribute.Order property, which is clearly a good idea. So the only thing we disagree on is whether the implicit control available in .NET 1.x is sufficient. The answer is yes, as long as you are aware of the issue and exercise due care. I've never seen this be a problem, but this is the heart of Craig's concern (Adam commented on Craig's post that he did see this problem - Adam, please fill me in with details, I want to understand what happened!). Specifically, he says “reordering type members is just too easy for a developer to do without thinking about it“. My solution is to exercise tighter control over the set of types you use for your Web service contract. If you actually write XSDs first, you solve the problem by treating the .NET types generated from your schemas the same way you would type a .obj file. If you write code first, treat those types the way you would treat any external interface that other parties consume. You don't let developers change those willy-nilly do you? One way to enforce this is to put these types in a seperate assembly that's owned by a dev-architect.

 


Posted Apr 18 2006, 02:54 PM by tim-ewald

Comments

clemensv@microsoft.com (Clemens Vasters [MSFT]) wrote Re: Craig remains jumpy about XmlSerializer and element order...
on 04-18-2006 1:38 PM
Go Tim, Go!
CraigBlog wrote The Perils of WSDL First (Again)
on 04-19-2006 5:59 AM
Jay wrote re: Craig remains jumpy about XmlSerializer and element order...
on 04-20-2006 5:42 AM
It seems to me that there is an issue with your "don't let developers change the order willy-nilly" comment. Over the lifetime of your project how do you enforce this?

Admittedly you can comment/document to reduce the risk but unfortunately I've known too many developers that just don't read what's in front of their face.

To me implicit just seems to fall into the tribal lore category of things that you need to know.


MikeJ wrote re: Craig remains jumpy about XmlSerializer and element order...
on 07-18-2006 12:12 PM
I have a somewhat similar problem...

I have a class that implements a xml choice element.

A client used a java proxy generator. That proxy generator created a class that has a constructor which is accepts all of the choices as parameters ( I assume that only one of them can be non-null )

The ordering of the parameters matches the ordering in the WSDL.

But that WSDL ordering has changed during a recent re-build. I can't find any reason for the change nor any way to control the ordering.

The 'Order' property of the XmlElement attribute can't be used to control the odering of the choices.

Ordering of the attributes doesn't seem to matter either.

I'm using the 2005 web depolyment project which may or may not be contributing to the problem.


MikeJ wrote re: MikeJ and XML choice
on 07-21-2006 7:18 AM
I heard back from Microsoft Support. They can reproduce the problem and it's not due to the web deployment.

But from their point of view the real problem is with the proxy generator; XML choice is by it's definition un-ordered so the proxy generator shouldn't introduce an ordering dependency.

That's a cop out from my point of view. Although I agree the Apache Axis proxy generator is doing something stupid there still shouldn't be a situation where the WSDL changes with a rebuild.

I still have not heard exactly what is causing the ordering to change. But the only work around they could suggest is to use a static hard coded WSDL.


Add a Comment

(required)  
(optional)
(required)  
Remember Me?