locked
Can't set default value to DataMember RRS feed

  • Question

  •  

    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; 
    } 
    Monday, March 7, 2011 3:22 PM

Answers

  • When you imported your service and it created a version of the ServiceControl class in your client for you, it only looks as the data, not the code. The fact that you wrote code to set a default value on your class is not copied, only the fact that you have 2 decimal values called Value1 and Value2.

    If you require those default values in your client, the only solution I can think of is to put the ServiceControl class into a DLL that you share with the client program, and then tell the client to reuse existing class from that DLL when you inport the web service reference.


    Please mark the post if it answers your question.
    • Marked as answer by ronili2 Monday, March 7, 2011 8:35 PM
    Monday, March 7, 2011 8:07 PM

All replies

  • When you imported your service and it created a version of the ServiceControl class in your client for you, it only looks as the data, not the code. The fact that you wrote code to set a default value on your class is not copied, only the fact that you have 2 decimal values called Value1 and Value2.

    If you require those default values in your client, the only solution I can think of is to put the ServiceControl class into a DLL that you share with the client program, and then tell the client to reuse existing class from that DLL when you inport the web service reference.


    Please mark the post if it answers your question.
    • Marked as answer by ronili2 Monday, March 7, 2011 8:35 PM
    Monday, March 7, 2011 8:07 PM
  • Thanks,

    This is my first WCF service application ...

    What do you mean by putting the service control class into DLL ?

    Can you please explain.

     

     

    Monday, March 7, 2011 8:36 PM