I'm trying to POST a list or array of values that are automatically deserialized to a complex object called RejectModel. This works perfectly when receiving the data as JSON, but when sending XML data, the automatic serializer makes rejectionList NULL.
I have tried using the default Xml serializer instead of the dataContract serializer. This gives me the following error:
No MediaTypeFormatter is available to read an object of type 'List'1' from content with media type 'application/xml'.
I have tried changing the list to an Array with the same results.
I feel like I'm just not naming my XML containing element correctly. Any suggestions would be appreciated.
Post declaration. Accept a list of rejectModels.
public HttpResponseMessage Post(List<RejectModel> rejectionList)
{
if (rejectionList == null)
{
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "The request was empty, malformed, or did not include an array of values.");
}
else if (rejectionList.Rejections.Length == 0)
{
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "An empty array was passed.");
}
}
Reject Model, I want to accept a list/array of these
[DataContract]
public class RejectModel : BaseModel
{
[Required]
[DataMember(IsRequired = true)]
public int LeadId { get; set; }
[DataMember]
public int? PropertyId { get; set; }
[DataMember]
public string PartnerPropertyId { get; set; }
[DataMember]
public string OriginalSource { get; set; }
[DataMember]
public DateTime OriginalReferralDate { get; set; }
}
One of my many request attempts. I have tried many tag names for "rejectList". I include "Accept: application/xml" in the request header.
<?xml version="1.0" encoding="UTF-8"?>
<rejectList>
<RejectModel>
<LeadId>10102085</LeadId>
<PropertyId>60278</PropertyId>
</RejectModel>
</rejectList>