How to serialize nullable DateTime in a .net web service?
-
03-07-2019 - |
Question
I am trying to pass some Subsonic collections to a client via a web service. When I reference the web service the IDE complains with:
Cannot serialize member 'EndDate' of type System.Nullable`1[System.DateTime]. XmlAttribute/XmlText cannot be used to encode complex types.
Is there any way of serializing nullable complex types in a .net web service?
Solution
The way you handle optional properties is to include a boolean XXXSpecified member where XXX is the name of the property. Nullable types are not handled properly by the xml serializer used by ASMX. Note that this is not a limitation of WCF.
OTHER TIPS
This is a .NET Limitation
If you want you can try generating your classes with this property in the SubSonicService section in the the web.config file.
generateNullableProperties="false"