I’m putting together a plan for an Xml web service to go into a client’s site to be consumed by third-parties so that they can access the client’s data.
My question is really asking about best practises here, and at the moment I am deliberating over 2 different strategies:
1) Create an object model which represents my Xml data and serialize it (either explicitly, or implicitly by exposing the data through a Wcf REST endpoint)
2) Transforming my domain model directly into hand-crafted Xml using XLinq and returning this as a string from the service, setting up the response headers appropriately
I like (1) because I let the system do the generation of the physical Xml and I work purely within the object model, but versioning becomes a problem and I might need finer control over the output.
I like (2) because I do get the fine control and versioning becomes easier, but I’m now hand-crafting Xml and the opportunity for error escalates.
Any opinions? Am I missing something which gives me the best of both worlds? I would go straight for (1) if I knew the best way to ‘version an object model’ – would using different namespaces suffice?
I’d use serialization. As long as you don’t try to use your domain objects for serialization you can get pretty fine grained control over the XML either via the DataContractSerializer or the XmlSerializer. You can then map between your domain objects and your serialization objects using something like AutoMapper