As a "side effect" of my current project, I am helping my client build a SOA interface to another large system. This client has traditionally used datasets for most of their data access, and one of my goals is to get the harsh dataset monkey off their backs and wean them onto the smooth, mellow high of business domain objects. After all, all the really cool Enterprises are doing it! I'm also trying to champion the "One interface to rule them all" cause, so this (eventually) will be the ONE and ONLY way to get data from, or put data in this system.
In putting together a proof of concept, I came across a bit of a problem; my entity has several properties that return lists of items. Some of these lists can be quite large, so we want to lazy load them. For my example, I created a person, who had a list of four address (I’m just returning four hard-coded ones since I didn’t want to muck with the database for the proof of concept) which I wanted to lazy load. I wired everything up and it was working beautifully!
Except for one thing; I was getting eight addresses back.
Here’s the problem; when the web service was getting ready to send my person object back, it was serialized by the XML serializer. That serializer was looking at my address property, which caused a lazy load. So, my object was initially coming over the wire with all the lists populated. One the client side, the de-serialization was also calling the address property, which was again lazy loading the address right away. I had a check in the “get” to make sure the list was null before the loading occurred, so how BOTH lists got merged together is something I can only wildly speculate about at this point, but it was merely a side effect of a different problem, so I didn’t worry about it.
The solution was to find a way for the XML Serializer to ignore that property when it was sending it out.
The solution: the XMLIgnore attribute. Decorating my property with this attribute causes the serializer to skip it. It doesn’t get looked at during serialization, it’s ignored during de-serialization and my lazy load routine work beautifully.
And all was well in the kingdom of SOA (for now…)