c# - Force WCF XML Serializer to include empty strings -
i have following property in struct
being returned wcf service:
[xmlattribute] public string batchid;
in cases value of batchid empty string, serialization excludes property resulting xml if never included in object begin with. how can force serializer include property, if empty string?
edit: using base xml serializer , not datacontract serializer emitdefaultvalues not option.
try use datamemberattribute emitdefaultvalue = true
:
[xmlattribute, datamember(emitdefaultvalue=true)] public string batchid_sched;
the emitdefaultvalue
cannot used xml serializer.
i think way implement ixmlserializable
interface , manually serialize/deserialize fields/properties of class:
public class test:ixmlserializable { public string prop; public void writexml (xmlwriter writer) { writer.writeattributestring("prop", prop ?? ""); } public void readxml (xmlreader reader) { if(reader.hasattributes) { prop = reader.getattribute("prop"); } } public xmlschema getschema() { return null; } }
Comments
Post a Comment