I’ve created an asp.net web service for a client of ours which returns multiple List objects containing complex types. The client has been receiving data just fine.
He has noticed though that not all the tags are there all the time. If, for example, I return 3 objects in my list, objects A B and C. and C is null when I return it. It will show:
<A>data</A>
<B>data</B>
When I would like it to show the following:
<A>data</A>
<B>data</B>
<C/>
Or at least:
<A>data</A>
<B>data</B>
<C></C>
Basically, I want the structure of the XML to remain the same regardless of what data is available and what data is null.
Any suggestions?
Thanks a lot!!
Soap spec. states:
Unfortunately for You MS has chosen first option for this situation.
On the other hand you could not make NULL value like this:
because how would You differ between empty string and null?
This option
looks promising. I’m guessing your service uses XMLSerializer to serialize your data. Check this post. Maybe you can implement
IXMLSerializablefor your object and provide custom xml for your data.