Reputation: 71
I've been banging my head against a wall for the past 2 days about this. For our client we need to make an interface that accepts XML (SOAP) messages in our API (.NET Core 3.1 or .NET 5). I'm at the point where the messages are finally coming in but they're always incomplete/null/default as you can see on the picture.
What is sent by the client (example 1):
What is received in our API:
And if we receive an XML with multiple lists, the lists are null (example 2):
What is going on here? Am I missing something?
Edit:
if i arrange the XML alphabetically, it works:
And yes in my Startup i used the XmlSerializers:
If I use .AddXmlSerializerFormatters() i can't even send the XML.
Upvotes: 3
Views: 967
Reputation: 7190
I tested your code, you can check my step.
TestXML:
public class TestXML
{
public int ID { get; set; }
public string Name { get; set; }
public List<TestXML_UoM_Item> TestXML_UoM_List { get; set; }
}
public class TestXML_UoM_Item
{
public string Name { get; set; }
}
XML:
<TestXML>
<TestXML_UoM_List>
<TestXML_UoM_Item>
<Name>aa</Name>
</TestXML_UoM_Item>
<TestXML_UoM_Item>
<Name>bb</Name>
</TestXML_UoM_Item>
</TestXML_UoM_List>
<ID>3</ID>
<Name>Gert</Name>
</TestXML>
StratUp:
services.AddControllersWithViews().AddXmlSerializerFormatters().AddXmlDataContractSerializerFormatters();
Action:
[HttpPost]
public void PostMds([FromBody]TestXML request)
{
//do your logic..
}
Upvotes: 2