I have the following xml document, which is submitted ( POST ) with an System.Web.Http.ApiController.
The code of the controller ( POST ) is pretty basic:
<ResponseType(GetType(Representative))>
Function PostRepresentative(ByVal model As Representative) As IHttpActionResult
If Not ModelState.IsValid Then
Return BadRequest(ModelState)
End If
RepresentativeRepository.Add(model)
UnitOfWork.Commit()
' db.Representative.Add(Representative)
' db.SaveChangesAsync()
Return CreatedAtRoute("DefaultApi", New With {.id = model.Id}, model)
End Function
And here is the document i'm submitting in the POST
<?xml version="1.0" encoding="UTF-8"?>
<Representative xmlns="http://schemas.datacontract.org/2004/07/Omnisoft.Domain.Slave" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Id>8</Id>
<Commission>10</Commission>
<Email />
<receiveInvoice>true</receiveInvoice>
<receiveDeliveryNotice>true</receiveDeliveryNotice>
<receiveEstimate>true</receiveEstimate>
<receiveOrderConfirmation>true</receiveOrderConfirmation>
<receiveRappel>true</receiveRappel>
<receiveCollectedBilling>true</receiveCollectedBilling>
<receiveWorkOrder>false</receiveWorkOrder>
<Name>TESTING</Name>
</Representative>
This is my corresponding model:
Public Class Representative
<Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)> _
Public Property Id As Integer
Public Property Name As String
<LocalizedDisplayName("Commission", NameResourceType:=GetType(ViewRes.RepresentativeValue))>
Public Property Commission As Double
<DataType(DataType.EmailAddress)> _
Public Property Email As String
Public Property receiveEstimate As Boolean
Public Property receiveOrderConfirmation As Boolean
Public Property receiveDeliveryNotice As Boolean
Public Property receiveInvoice As Boolean
Public Property receiveCollectedBilling As Boolean
Public Property receiveWorkOrder As Boolean
Public Property receiveRappel As Boolean
End Class
When the xml document puts Name as the last property, it doesn't get submitted in the model. When it's submitted at the top of the XML file. Odata can "parse/serialize" the property and there is no problem.
Otherwhise, my added entity contains a nil value for Name.
Any ideas what this could be?
答案 0 :(得分:-1)
我使用了不同的xml序列化程序,并且有效。