I'm writing a .NET Core 3.1 Client for a WCF Service. I generated a client with svcutil. All members in reference.cs have the following attribute:
[System.Xml.Serialization.XmlElementAttribute("property.name", IsNullable = true, Order = 0)]
Some elements should not be serialized in the messaged when they are null, i.e.: Currently all elements are included:
<criteria>
<criteria1 xsi:nil="true"/>
<criteria2>1</criteria2>
<criteria3 xsi:nil="true"/>
</criteria>
The desired result:
<criteria>
<criteria2>1</criteria2>
</criteria>
In .Net Framework I was able to add the attribute [DataMember(EmitDefaultValue=false)] to get the correct behavior, this is not supported in .NET Core.