I can de-serialize the XML in my ASP.net Web API project in post request successfully,
XML:
<Request xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/TestAPI.Models">
<Child>
<CountryISO>
<country xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d4p1:string>CA</d4p1:string>
<d4p1:string>US</d4p1:string>
</country>
</CountryISO>
</Child>
</Request>
Model
namespace TestWebTuiAPI.Models
{
public class Request
{
public Trip Child{ get; set; }
}
public class Child
{
public CountryISO CountryISO { get; set; }
}
public class CountryISO
{
[XmlElement("country")]
public List<string> country { get; set; }
}
}
Now,I need do all the above steps to make my Post Request working in the ASP .Net Web API. If I remove the [XmlElement("country")] attribute from the model, the CountryISO tag in the XML returns null or empty value.
what I want to achieve here is to de-serialize the following XML successfully using POST request,
XML:
<Request>
<Child>
<CountryISO>
<country>CA</country>
<country>US</country>
</CountryISO>
</Child>
</Request>
If I try to post this above XML, I'm getting an invalid request and I'm receiving a null model. I need to add the headers(parent node and CountryISO node) in the first XML to make it work successfully. I've tried various solutions but in vain.
Any advice will be much appreciated.
EDIT: if I use
config.Formatters.XmlFormatter.UseXmlSerializer = true;
I don't need the headers but I'm getting empty values inside the CountryISO tag ?