Craig recently wrote about his experiences using a contract-first approach to building Web Services. He called it
The Perils of WSDL First. Craig essentially urges anyone starting with WSDL to implement IXmlSerializable on their types given the lack of control over element order in XmlSerializer 1.1. Tim responded saying
what Craig urges is overkill.
Although what Craig describes is definitely an issue, I agree with Tim that you don't have to go nearly that far. In fact, I know many customers who have succesfully built services using a WSDL-first approach without having to know hardly anything about the System.Xml.Serialization stack. What did they do differently?
They relied on a code-generator (xsd.exe) to produce the serializable types used at the edges of the system (the external types) -- and they considered this code immutable -- they only change it when there's a change to the WSDL definition and they need to regenerate the whole service layer. Then they manually defined internal (domain specific) types, with all the bells and whistles they desired along with transformation logic for moving between the internal/external types. This is basically what Craig suggests you should do in his set of rules at the bottom of his post.
Doing this guarantees that the external "serializable" types will always produce the correct XML as defined by the original schema, but within the business/data layers you can use friendlier types to your liking (e.g., different member order, helper methods and properties, etc). It also allows you to host multiple service endpoints, each supporting a different WSDL version, but all endpoints are implemented against the same internal domain-specific types. If you use this approach, you won't experience the problem Craig describes.
In general, I consider it a no-no to modify any code generated from WSDL if you're sharing the original WSDL definition with consumers -- there are just too many things that can cause violations to the contract, order being one of them.
Posted
Apr 18 2006, 02:32 PM
by
Aaron Skonnard