wcf - Why is the public property not being serialized? -


we have wcf service includes serializable classes in contract has datacontract , datamember @ root level of service.

while trying build solution isolate problem, came across following:

[servicecontract] public interface iservice1 {     [operationcontract]     compositetype getdatausingdatacontract();  }   [datacontract] public class compositetype {     [datamember]     public mytype myproperty { get; set; }  }  [serializable] public class mytype {     private int amount1;      [xmlelement(form = xmlschemaform.unqualified, datatype = "int", elementname = "amountn")]     public int amount1     {                 { return amount1; }         set         { amount1 = value; }     }   } 

gives following xsd:

<xs:complextype name="compositetype">  <xs:sequence>   <xs:element name="myproperty" type="tns:mytype" nillable="true" minoccurs="0"/>  </xs:sequence> </xs:complextype><xs:element name="compositetype" type="tns:compositetype" nillable="true"/> <xs:complextype name="mytype">   <xs:sequence>    <xs:element name="amount1" type="xs:int"/>   </xs:sequence>  </xs:complextype>  <xs:element name="mytype" type="tns:mytype" nillable="true"/> </xs:schema> 

question is: why private not public member being serialized?

serializers , serialization attributes 2 different things.

xmlelement attribute xmlserializer has no meaning datacontractserializer or binaryformatter. xmlelementattribute class

datacontractserializer can serialize multiple types, uses own serialization algorithm link. when serializing objects marked [serializable], datacontractserializer follows default serialization pattern (serializing members, [nonserialized] applies). if need more control can implement iserializable custom serialization , can set node names , values in serialized object serialization .

there option implement ixmlserializable , have full control on how serialized object like.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -