Search code examples
serializationnamespacesdatacontractdatacontractserializerdatamember

Adding a DataMember to a different namespace to the DataContract


With the XmlSerializer I can have my members in different namespaces to the parent type.

Can I do the same thing with DataContractSerializer?

I would like the following XML:

<h:Type xmlns:h="http://schemas.e.com/WebServices"
    xmlns="http://schemas.e.com/WebServices">
  <Member xmlns="http://schemas.e.com/CoreTypes">0</Member>
</h:Type>

Is this possible in with DataContractSerializer?


Solution

  • You can define subdatacontracts in different namespaces and use them as members of another datacontract, but you can't control the individual member names and/or shapes. The DataContractSerializer isn't intended to replace XmlSerializer for fine-grained control of the "shape" of your XML.