We are facing multiple issues with xml searilization of ASP.NET WebAPI. Currently we are using xmlserializer
instead of DataContractSearilizer
(which is a default serialization method for XML serialization) for two basic reasons.
In
DataContractSearlizer
We need to pass all the fields of object in ascending order otherwise getting null at api end.We also need to pass namespace in XML header for passing XML object to web api.
For these two basic reasons we decided to go for xmlserializer
instead of DataContractSearlizer
. But now we are facing another issue which was not present in default DataContractSearilization
mechanism. Let say we have an object like this
[DataContract]
public class Car
{
public int ID;
[DataMember]
public string CarName;
[DataMember]
public string CarType;
}
Now we were expecting that on client end we will only receive the those fields surrounded by DataMember attribute but unexpectedly we are getting all the fields whether DataMember attribute present or absent. This is perfectly working fine in json searlization and result was what we were initially expected. Can someone help us in this regard?