Search code examples
wcfdatacontract

Can't set default value to DataMember


I have class that is a DataContract and the member values are holding default values. When i create object of this type in the client machine i don't see that the default values are set.

The Class:

[DataContract]
public class ServiceControl
{
    [DataMember(EmitDefaultValue = false)]
    public decimal Value1 = 1.0m;

    [DataMember( EmitDefaultValue = false )]
    public decimal Value2 = 1.0m;
}

Solution

  • Most probably since you are using a "Add Service Reference". This will only copy the definition using WSDL and will not contain any code or business logic in your classes.

    UPDATE

    You can reuse your0 DTO/Entities:

    • Clicking the box reuse types from referenced assemblies and making sure you are referencing the assembly defining DTO
    • Reference assembly and create your proxies using channel factory