none
June CTP - EmitDefaultValue and nillable RRS feed

  • Question

  • From an earlier post, EmitDefaultValue attribute in DataMember is supposed to help controlling xsi:nillable attribute in data contracts. However it has no effect on that attribute on a given data member definition. If we are stuck with using EmitDefaultValue, then it certainly is not interoperable non-WCF code as it is custom information in the generated xsd.

    Is there going to be a way to control this attribute directly in future releases?

    Thanks.

    Thursday, July 13, 2006 10:52 PM

Answers

  • Raghu,

    The EmitDefaultValue as the name suggest help you control the serialization of the default value. For example, if the DataMemeber type is int then EmitDefaultValue=false will not emit 0, which is default(int). This will result in minoccurs=0 in the schema. For the reference types or nillable<T> (nillable<int> for example) the default value is null. Thus by specifying EmitDefaultValue=true for the nillable types (reference types or nillable<value types>) the schema will produce nillable=true and the wire will use xsi:nil for the null value.

    Let me know if you have specific question regarding your scenario.

    Thanks,

    Vipul Modi [MSFT]

    Friday, July 14, 2006 9:55 PM
    Moderator

All replies

  • Raghu,

    The EmitDefaultValue as the name suggest help you control the serialization of the default value. For example, if the DataMemeber type is int then EmitDefaultValue=false will not emit 0, which is default(int). This will result in minoccurs=0 in the schema. For the reference types or nillable<T> (nillable<int> for example) the default value is null. Thus by specifying EmitDefaultValue=true for the nillable types (reference types or nillable<value types>) the schema will produce nillable=true and the wire will use xsi:nil for the null value.

    Let me know if you have specific question regarding your scenario.

    Thanks,

    Vipul Modi [MSFT]

    Friday, July 14, 2006 9:55 PM
    Moderator
  • Vipul,

    I have a question on this again. I am using July CTP.

    If I have a string member in a data contract and it is marked as required, one can can still send that particular string in the format <MyMember xsi:nil"true" />. The same appears to be true for all reference types.

    Lets says that we did use EmitDefaultValue with a value of false.

    Will the consumers (lets from java world) will be able to call the service with null value for reference types (<MyReferenceTypeMember xsi:nil"true" />)? Does it mean we always have to check for null of reference types in the service implementation even though we marked them as required?

    Thanks.

    Wednesday, September 27, 2006 10:40 PM